Guest User

Untitled

a guest
Aug 14th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. '''
  2. Terrance Blount
  3.  
  4. A function that returns the count of prime numbers that exist ep to and including a giving number.
  5. '''
  6.  
  7. def count_primes(num):
  8. primes = [2]
  9. x = 3
  10. if num < 2: # for the case of num = 0 or 1
  11. return 0
  12. while x <= num:
  13. for y in range(3,x,2): # test all odd factors up to x-1
  14. if x%y == 0:
  15. x += 2
  16. break
  17. else:
  18. primes.append(x)
  19. x += 2
  20. print(primes)
  21. return len(primes)
  22.  
  23. print(count_primes(25))
Add Comment
Please, Sign In to add comment