Write a python program to check if a given 3-digit number
X is an Armstrong number or not. Note: A number is an Armstrong number if the number is equal to the sum of the Nth power of its digits.
try:
n = int(input('n = '))
if n <= 100 or n > 999:
raise ValueError
p = len(str(n))
s = 0
for i in range(p):
s += int(str(n)[i])**p
if s == n:
print(f'{n} is an Armstrong number')
else:
print(f'{n} is not an Armstrong number')
except ValueError:
print('incorrect inpur')
Comments
Dear kaavya the code works well
unable to get the right output. Few errors are araising like in the above code s is not defined....
Leave a comment