Peragon


Joined 1 year ago
Homeworks submitted:
Homework comments:
2
1

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 11% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1

ps1a Name: Peragon Time: 04:30:00 Collaborators: none

I had a bunch of trouble on the first part, and had to resort to looking up other student's solutions to adapt them for myself. Thank you Duallain! The second part only took about thirty minutes.

# This my solution to problem 1
number = int(raw_input('What prime would you like to find? ')
list_of_primes = [2]
number_of_primes = 1
testing_number = 3
def primality(n):
	for a in list_of_primes:
		if n % a == 0:
			return False
	return True
while number_of_primes <= number-1:
	if primality(testing_number) == True:
		list_of_primes.append(testing_number)
		number_of_primes += 1
		testing_number += 2
	else:
		testing_number += 2
# Here is problem 2
from math import *
while continuity == False:
	def generate_primelist(z):
		list_of_primes = [2]
		number_of_primes = 1
		testing_number = 3
		def primality(n):
			for a in list_of_primes:
				if n % a == 0:
					return False
			return True
		while list_of_primes[-1] != z:
			if primality(testing_number) == True:
				list_of_primes.append(testing_number)
				number_of_primes += 1
				testing_number += 2
			else:
				testing_number += 2
		return list_of_primes
	def take_log(list_of_primes):
		sum_of_logs = 0
		for a in list_of_primes:
			sum_of_logs += log(a)
		return sum_of_logs
	prime = int(raw_input('Please enter a prime to test: ')
	prime_list_z = generate_primelist(prime)
	prime_log = take_log(prime_list_z)
	print 'Your number is: ', prime
	print 'The natural logarithm of all the primes up to your number is : ', prime_log
	print 'The ratio of these two quantities is: ', prime_log/n, '\n'
	continuity = 'Do you wish to continue? y/n: '
	if continuity == y:
		continuity == True
	else:
		continuity == False

Peragon 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1

Problem Set 0 Name: Peragon Time: 30 seconds

first_name = raw_input('What is your first name? ')
last_name = raw_input('What is your last name? ')
print first_name
print last_name

Peragon 1 year ago