brewersfan1976

ch2-ex13.py

Jul 5th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. def divisors(num):
  2.     div = 1
  3.     amount = 0
  4.    
  5.     while (div <= num):
  6.         if (num % div == 0):
  7.             amount = amount + div
  8.         div = div + 1
  9.     return amount
  10.    
  11. x = 1
  12. perfect_number= 0
  13.  
  14. while (perfect_number < 3):
  15.     result = divisors(x)
  16.    
  17.     if (result == x * 2):
  18.         print x, "is a perfect number"
  19.         perfect_number = perfect_number + 1
  20.    
  21.     x = x + 1
Advertisement
Add Comment
Please, Sign In to add comment