brewersfan1976

ch2-ex11.py

Jul 4th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. def divisors(num):
  2.     count = 1
  3.     div = 2
  4.    
  5.     while (div < num):
  6.         if (num % div == 0):
  7.             count = count + 1
  8.         div = div + 1
  9.     return count
  10.    
  11. x = 4
  12.  
  13. prime_numbers = []
  14.  
  15. while (x <= 100):
  16.     result = divisors(x)
  17.    
  18.     if (result == 1):
  19.        prime_numbers = prime_numbers + [x]
  20.        
  21.     x = x + 1
  22.  
  23. y = 2
  24. prime_number_divisible = False
  25.  
  26. while (y <= 100):
  27.     for x in prime_numbers:
  28.           if (y % x == 0):
  29.              prime_number_divisible = True
  30.              
  31.     if ((y % 2 == 0 or y % 3 == 0) and prime_number_divisible == False):
  32.           print y, "is divisible by 2 or 3 but not by any other prime number"
  33.          
  34.     y = y + 1
  35.     prime_number_divisible = False
Advertisement
Add Comment
Please, Sign In to add comment