Skip to content

Instantly share code, notes, and snippets.

@newsundram2018
Created August 24, 2019 10:45
The below function is written to check whether a given three digit number is an Armstrong number. Hint: An “Armstrong number” is an n-digit number that is equal to the sum of the nth powers of its individual digits. Example: 371 is an Armstrong number as 371 = 3^3 +7^3+ 1^3
'''
Created on 24-Aug-2019
@author: Anonymous
'''
#PF-Tryout
def find_armstrong(number):
temp=0
x=number #
while(number!=0):
remainder=number%10
# This Statement changing the value of number variable so
number=number//10
# For keeping original Number we took it in a variable named a "x"
temp+=(remainder*remainder*remainder)
if(x==temp):
return True
return False
number=371
if(find_armstrong(number)):
print(number,"is an Armstrong number")
else:
print(number,"is not an Armstrong number")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment