Answer to Question #215650 in Python for kaavya

Question #215650

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.


1
Expert's answer
2021-07-09T14:19:29-0400
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')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
11.07.21, 21:52

Dear kaavya the code works well

kaavya
10.07.21, 05:00

unable to get the right output. Few errors are araising like in the above code s is not defined....

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS