Completed a week or two ago, didn't realize there was an online submission at the time. CC welcome on all submissions.
#Problem Set 1, Problem 1
#Name: Charlie Roselius
#Collaborators: None
#Time: Approximately 0:30 (completed earlier)
#
primes_found = 1 #Start testing numbers at 3, so 2 has been found.
potential_prime = 1 #Initialized, but will be 3 in first loop.
while primes_found < 1000: #The 1000th prime will be the last iteration of this loop.
potential_prime += 2 #Only check odd numbers.
is_prime = 1 #Litmus variable for result of prime test.
for i in range(2,potential_prime): #Iterate over potential divisors.
if potential_prime % i == 0: #If remainder is zero, we found a divisor and...
is_prime = 0 #the number is not prime...
break #so we can stop testing for more divisors.
if is_prime == 1: #If we weren't able to find any divisors, this number is prime.
primes_found += 1 #Increment our prime counter, loop back to beginning of while block and check for whether this was the 1000th prime.
print potential_prime #As the last iteration of the while loop will have been the 1000th prime, we can simply print this.
#Problem Set 1, Problem 2
#Name: Charlie Roselius
#Collaborators: None
#Time: Approximately 0:30 (completed earlier)
#
from math import * #Needed to compute logs.
print "Please enter n"
n = int(raw_input()) #CCREQUEST: Is n a good variable name?
sum_of_logs = 0
potential_prime = 1 #We need to identify the primes to use in our sum of logs. Please refer to above for algorithm comments.
while potential_prime<n+1:
is_prime = 1
for i in range(2,potential_prime):
if potential_prime % i == 0:
is_prime = 0
break
if is_prime == 1:
sum_of_logs += log(potential_prime) #Sum the primes as we come across them.
potential_prime += 2
#Now we can print our results.
print "The sum of the logs of the primes is: " + str(sum_of_logs) + "\n"
print "N was: " + str(n) + "\n"
print "Their ratio is: " + str(sum_of_logs/n)
Completed a week or two ago, didn't realize there was an online submission at the time. CC welcome on all submissions.
#Problem Set 0
#Name: Charlie Roselius
#Collaborators: None
#Time: Approximately 0:15 (completed earlier)
#
print ("What is your last name?")
last_name = raw_input()
print ("What is your first name?")
first_name = raw_input()
print ("Your name is: " + first_name + " " + last_name)