Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #this program will find the first 1000 prime numbers and add them to the list of prime numbers
- def primecheck(number):
- counter = 0 #resets the counter to 0, this counts the number of times
- #a number is evenly divided by a number in the primelist
- for j in primelist:
- if number%j == 0:
- counter += 1
- return counter #this step returns the number of times a number was divided
- #if it is 0, then it is a prime number
- primelist = []
- number = 2
- while len(primelist) < 1000: #1000 is the number of primes we want to find
- if primecheck(number) == 0: #checks to see if a number is a prime
- primelist += [number,] #adds number to the list
- number += 1
- else:
- number += 1
- print primelist #prints result
Advertisement
Add Comment
Please, Sign In to add comment