Guest User

ps1#1

a guest
Feb 12th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #this program will find the first 1000 prime numbers and add them to the list of prime numbers
  2.  
  3. def primecheck(number):
  4. counter = 0 #resets the counter to 0, this counts the number of times
  5. #a number is evenly divided by a number in the primelist
  6. for j in primelist:
  7. if number%j == 0:
  8. counter += 1
  9. return counter #this step returns the number of times a number was divided
  10. #if it is 0, then it is a prime number
  11.  
  12. primelist = []
  13. number = 2
  14. while len(primelist) < 1000: #1000 is the number of primes we want to find
  15. if primecheck(number) == 0: #checks to see if a number is a prime
  16. primelist += [number,] #adds number to the list
  17. number += 1
  18. else:
  19. number += 1
  20. print primelist #prints result
Advertisement
Add Comment
Please, Sign In to add comment