Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. import math
  2.  
  3. #Display all prime numbers from 1-100
  4.  
  5. def main():
  6.    
  7.     print('Here are all the prime numbers from 1 to 100')
  8.    
  9.     for num in range(1, 101):
  10.         result = is_prime(num)
  11.         if result:
  12.             print(result)
  13.         else:  
  14.             pass
  15.    
  16.        
  17. def is_prime(num):
  18.     squared_num = math.sqrt(num)
  19.     squared_num = int(squared_num)
  20.     if num % 2 == 0:
  21.         return False
  22.     for x in range(3, squared_num + 2, 2):
  23.         if num % x == 0:
  24.             return False
  25.     return num
  26.    
  27. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement