Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 10 Online
OpenStudy (anonymous):

Does anyone have an idea of computing prime numbers with python?

OpenStudy (anonymous):

One possible implementation is the following: def primes(n): if n==2: return [2] elif n<2: return [] s=range(3,n+1,2) mroot = n ** 0.5 half=(n+1)/2-1 i=0 m=3 while m <= mroot: if s[i]: j=(m*m-3)/2 s[j]=0 while j<half: s[j]=0 j+=m i=i+1 m=2*i+3 return [2]+[x for x in s if x] Taken from http://code.activestate.com/recipes/366178-a-fast-prime-number-list-generator/

OpenStudy (anonymous):

Another nice web site. http://www.thattommyhall.com/2010/10/18/prime-gen/ Please note that I haven't tested any of the above code myself!

OpenStudy (anonymous):

just try out this prime_count = 1 start_number = 2 number_to_check = 2 while prime_count <= 1000: result = number_to_check % start_number if result > 0: start_number +=1 elif result == 0: if start_number == number_to_check: print (number_to_check) number_to_check +=1 prime_count +=1 start_number =2 else: number_to_check +=1 start_number = 2

OpenStudy (anonymous):

http://dpaste.com/807530/

OpenStudy (anonymous):

Check out this Khan academy CS lesson on computing prime numbers. http://www.khanacademy.org/about/blog/post/32465397255/computer-science-prime-adventures-level-up It is done in their javascript environment and not in python tho.

OpenStudy (anonymous):

very cool! Thanks for all the help. :-)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!