Skip to content

Instantly share code, notes, and snippets.

@paul-schwendenman
Created February 19, 2015 04:23
Show Gist options
  • Save paul-schwendenman/fa8ab19f723a16e9df3f to your computer and use it in GitHub Desktop.
Save paul-schwendenman/fa8ab19f723a16e9df3f to your computer and use it in GitHub Desktop.
Perfect number
upper_bound = int(input("Upper bound: "))
n = 1
while n <= upper_bound:
factors = []
i = 1
while i < n:
if n % i == 0:
factors.append(i)
i += 1
if sum(factors) == n:
print(n)
n += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment