Created
February 23, 2019 20:04
-
-
Save r-malon/1c42c558e6122cbfabe877b47401ba99 to your computer and use it in GitHub Desktop.
Checks if a given number is an Armstrong number.
This file contains 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 armstrong(n): | |
n = str(n) | |
soma = 0 | |
for i in n: | |
soma += int(i)**len(n) | |
return soma == int(n) | |
if __name__ == '__main__': | |
number = 407 | |
print(f"Is {number} an Armstrong number? ", armstrong(number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment