Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

in ps1 i can generate primes but the problem with output is that it is painfully repetitive. the code is here http://codepad.org/9ZdIo1Cv suggestions and modifications required...... the output is like: 2 2 3 2 3 5 2 3 5 7 ......so on

OpenStudy (anonymous):

what output do you want? do you want to calculate all primes from 0 to n for a given input n?

OpenStudy (anonymous):

i want that output should not be repetitive as it is above. it should be continuous like 2 3 5 7 11 .....and so on

OpenStudy (anonymous):

def primes(n): s=range(0,n+1) s[1]=0 bottom=2 top=n//bottom while (bottom*bottom<=n): while (bottom<=top): if s[top]: s[top*bottom]=0 top-=1 bottom+=1 top=n//bottom return [x for x in s if x] Try that? print primes(131)

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!