Skip to content
Home ยป Python-Questions Any number, say ‘n’, is called an Armstrong number if it is equal to the sum of its digits, where each is raised to the power of the number of digits in ‘n’.

Python-Questions Any number, say ‘n’, is called an Armstrong number if it is equal to the sum of its digits, where each is raised to the power of the number of digits in ‘n’.

Python Question โ€“ 2

Armstrong Number

Any number, say ‘n’, is called an Armstrong number if it is equal to the sum of its digits, where each is raised to the power of the number of digits in ‘n’.

For example:

153=13+53+33

Code:

num=int(input()) sum = 0 
# find the sum of the cube of each digit
temp = num while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 
# display the result 
if num == sum: print("True") else: print("False")

Share this post on social

Mary Mathew

Mary Mathew

Mary Mathew is a Python web developer with a passion for creating beautiful and user-friendly websites. She also writes about the latest web development trends, Python libraries and tools.View Author posts

Leave a Reply

Your email address will not be published. Required fields are marked *