Table of Contents
Python program to check Armstrong number
Python program to check Armstrong number : For a given number if the sum of digits each raised to the power of number of digits then the it is Armstrong number.
E.g. 1634 = (1*1*1*1)+(6*6*6*6)+(3*3*3*3)+(4*4*4*4)
Total number of digits n = 4
Hence we have to calculate
14 + 64 + 34 + 44
Logic to check Armstrong number in python
"""
Author : ITVoyagers (https://itvoyagers.in)
Date :08th August 2018
Description : Python program to check if the number provided by the user is an Armstrong number or not.
"""
# take input from the user
num = int(input("Enter any number: "))
power=len(str(num))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** power
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output :
Enter any number: 371
371 is an Armstrong number
>>> ================================
Enter any number: 1634
1634 is an Armstrong number
>>> ================================
Enter any number: 121
121 is not an Armstrong number
We are aiming to explain all concepts of python in easiest terms as possible.

ITVoyagers
Author
PRACTICALS/PRACTICE PROGRAM IN PYTHON
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on File Handling |
Easy quiz on file handling in python part 1 |
Easy quiz on file handling in python part 2 |
Quizzes on Exception Handling |
Easy quiz on Exception Handling in python part 1 |
Easy Quiz on Exception Handling in python part 2 |
Quizzes on Regular Expressions |
Easy Quiz on Regular Expression in python part 1 |
Quizzes on Python concepts coming soon… |
Python basic quiz |
New and easy python quiz basic part 1 |
New and easy python quiz (basic) part 2 |
New and easy python quiz (basic) part 3 |
Python practice quiz set |
Best Practice Quiz Set on Python Programming Part 1 |
Best Practice Quiz Set on Python Programming Part 2 |
Best Practice Quiz Set on Python Programming Part 3 |
Best Practice Quiz Set on Python Programming Part 4 |
Best Practice Quiz Set on Python Programming Part 5 |