Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- allprimes = [1, 2, 3] # defines a variable as an array of primes
- candidate = 5 # defines a starting candidate
- while len(allprimes) < 1000: # starts a conditional loop under which the following steps will repeat
- for number in allprimes: # nests another loop -- for each number in the list of primes
- if candidate % number == 0: # if any number in the array of primes divides evenly into the candidate
- break # stop the loop
- else: # otherwise
- allprimes.append(candidate) # append the candidate to the end of the allprimes array
- candidate = candidate + 2 # redefine candidate as its previous value + 2
- if len(allprimes) == 1000: # when the length of the prime list reaches 1000
- print allprimes[-1] # print that last sucker out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement