MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
from math import *
def prime_counter():
odd = 1
max = 1
l = log(2)
n = raw_input('How many primes to count to?', )
while max <= int(n): #Sets up main loop
odd += 2 #incriments odd by 2 every new loop
for x in range(2, odd): #sets up loop with current odd value as range limit
non_zero = (odd % x) #uses current position in range (x) as modulus value
if non_zero is 0: #if there is no remainder its not prime
break #go to next number in max range
else: #if there is a remainder
continue #go to next number in x range
else: #if prime
print odd #print odd
max += 1 #incriment main loop by 1
l = l + log(odd)
else:
print 'max prime ' + str(odd)
print l
print (float(l)/float(n))
prime_counter()
m0nkeysensei
1 year ago