daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Aug 14th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top