Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- prime_candidate=3
- prime_counter=0
- #we are neglecting 2, so only go up to 999
- while prime_counter<999:
- prime_divisor=2
- ##prime_divisor is here so that it gets reset at the beginning of each round in the while loop
- while prime_divisor<(prime_candidate/2)
- if prime_counter%prime_divisor>0:
- ###checking to see if there is a remainder
- prime_divisor=prime_divisor+1
- prime_counter=prime_counter+1
- print prime_candidate
- prime_candidate=prime_candidate+2
- ##setting prime_candidate as the next odd number
- print prime_candidate 'is the 1000th prime'
- EDITED: V2.0
- prime_candidate=3
- #prime_candidate variable is the number being checked if prime
- prime_counter=0
- #prime_counter is keeping track of which prime number we are on
- #we are neglecting 2, so only go up to 999
- while prime_counter<999:
- prime_divisor=2
- ##prime_divisor is here(after the first while) so that it gets reset at the beginning of each round in the while loop
- while prime_divisor<(prime_candidate/2):
- ###since we are using integer division, it is ok to divide prime_candidate by 2, as the remainder will be thrown away
- if prime_counter%prime_divisor>0:
- ###checking to see if there is a remainder
- prime_divisor=prime_divisor+1
- if prime_counter%prime_divisor==0:
- ###if there is no remainder, it isn't prime, moving on to the next odd number
- prime_candidate=prime_candidate+2
- prime_counter=prime_counter+1
- print prime_candidate
- prime_candidate=prime_candidate+2
- ##setting prime_candidate as the next odd number
- print prime_candidate + 'is the 1000th prime'
- V3.(1):
- prime_number_candidate=1
- prime_counter=0
- while prime_counter<999:
- prime_number_candidate=prime_number_candidate+2
- primecheck=True
- prime_divisor=2
- ##initialized here so that they are reset at each round of the loop
- while prime_divisor<(prime_number_candidate/2):
- ###while loop to determine if the number is still prime after being divided by every number less than n/2
- if prime_number_candidate%prime_divisor>0:
- #### % operator to determine if there is a remainder
- prime_divisor=prime_divisor+1
- else:
- primecheck=False
- prime_divisor=prime_number_candidate+1
- prime_number_candidate=prime_number_candidate+2
- if primecheck==True:
- prime_counter=prime_counter+1
- print prime_number_candidate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement