-
-
Save tearp/23ba3dc0051e15887f66 to your computer and use it in GitHub Desktop.
Find abundant/deficient/perfect numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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