anonymous
  • anonymous
My first attempt at prob set 1... When I call the Find1000Prime function I get the right answer but there is a slight delay as if my code is very inefficient. Will anyone provide me with suggestions to improve this code? def isPrime(num): i = 2 if num == 1: return 0 if num == 2: return 1 while i <= num-1: if num%i == 0: return 0 else: i = i + 1 return 1 def Find1000Prime(): i = 2 j = 0 while j < 1000: if isPrime(i) == 1: j = j + 1 if j == 1000: return i i = i + 1
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Try using this algorithm. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
anonymous
  • anonymous
Awesome code! I was lost as to finding a function to i.d. prime numbers. But for efficiency- the range for the divisor does not have to be from 2 till number-1, rather 2 till sqrt(number) is sufficient http://en.wikipedia.org/wiki/Primality_test

Looking for something else?

Not the answer you are looking for? Search for more explanations.