Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- "PerfectNumbers.py"
- by Chris Clarke
- 13.12.2014
- '''
- def print_perfect():
- for n in range(1, 10000):
- sum_factors = 0 # reset
- output = "" # reset
- max = int(n/2) # highest factor of n is half of n
- for i in range(1, max+1):
- if n%i == 0: # i is a factor of n
- if (i==1): # first iteration of inner loop
- output = str(n)+" = 1"
- else: # 2nd, etc
- output += " + "+str(i)
- sum_factors += i
- if sum_factors==n: # ...it's perfect
- print output # print string
- def main():
- print "The perfect numbers are"
- print_perfect()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement