Skip to content

Instantly share code, notes, and snippets.

@tearp
Created December 1, 2015 05:07
Show Gist options
  • Save tearp/23ba3dc0051e15887f66 to your computer and use it in GitHub Desktop.
Save tearp/23ba3dc0051e15887f66 to your computer and use it in GitHub Desktop.
Find abundant/deficient/perfect numbers
def divisor(x):
y = []
for i in range(1, x):
if x % i == 0:
y.append(i)
return sum(y)
def determine(x):
if divisor(x) == (x):
print '{} ~~perfect~~'.format(x)
if divisor(x) < x:
print '{} ~~deficient~~ {}.'.format(x, (x - divisor(x)))
if divisor(x) > x:
print '{} ~~abundant~~ {}.'.format(x, (divisor(x) - x))
def test_cases():
divisor(111), determine(111)
divisor(112), determine(112)
divisor(220), determine(220)
divisor(69), determine(69)
divisor(134), determine(134)
divisor(85), determine(85)
divisor(6), determine(6)
if __name__ == '__main__':
test_cases()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment