Skip to content

Instantly share code, notes, and snippets.

@r-malon
Created February 23, 2019 20:04
Show Gist options
  • Save r-malon/1c42c558e6122cbfabe877b47401ba99 to your computer and use it in GitHub Desktop.
Save r-malon/1c42c558e6122cbfabe877b47401ba99 to your computer and use it in GitHub Desktop.
Checks if a given number is an Armstrong number.
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