Answer to Question #231098 in Python for umesh

Question #231098

3-digit Armstrong Number

Write a 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.Input

The first line is an integer

X.Output

The output should be a single line containing

True if it satisfies the given conditions, False in all other cases.Explanation

In the given example

X = 371, The number of digits in 371 is 3. So, 33 + 73 + 13 = 371. Hence,

371 is an Armstrong number.So, the output should be

True


1
Expert's answer
2021-09-01T23:58:17-0400
x = input()
length = len(x)
sum = 0

for i in x:
    sum += int(i) ** length
if sum == int(x):
    print(True)
    exit()
print(False)

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS