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
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
Join our real-time social learning platform and learn together with your friends!