Advertisement
cd62131

Perfect Number

Feb 8th, 2014
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. def is_perfect(n):
  4.     if n < 2:
  5.         return False
  6.     measure = []
  7.     for i in xrange(1, n / 2 + 1):
  8.         if n % i == 0:
  9.             measure.append(i)
  10.     return n == sum(measure)
  11.  
  12. if __name__ == "__main__":
  13.     for i in range(0, 1000):
  14.         if is_perfect(i):
  15.             print i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement