Skip to content

Instantly share code, notes, and snippets.

@alarsyo
Created May 11, 2016 13:35
Show Gist options
  • Save alarsyo/6a866007c707681fe2b7d3c13fca6438 to your computer and use it in GitHub Desktop.
Save alarsyo/6a866007c707681fe2b7d3c13fca6438 to your computer and use it in GitHub Desktop.
Perfect number
def sumDivs(n,accu, i):
if i > (n//2):
return accu
elif n % i == 0:
print(i)
return sumDivs (n, accu + i , i+1)
else :
return sumDivs (n, accu, i+1)
x = int(input("give n ? "))
print("les diviseurs de", x, "sont :")
if x < 1:
print("n must be > 1")
elif sumDivs(x, 0, 1) == x:
print(x, "is perfect")
else:
print(x, "isn't perfect")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment