Programming Examples

Python program to check whether given number is Armstrong or not


Write a program to input any number and to check whether given number is Armstrong or not.

Example:

Armstrong 153,

1^3+5^3 +3^3 =(1+125+27)=153

Solution

num=int(input("Enter any Number"))
sum=0
tmp=num
while num>0:
    digit=(num%10)
    sum=sum+digit**3
    num=num//10
if sum==tmp:
    print(tmp, " is Armstrong Number")
else:
    print(tmp, " is not Armstrong Number")
Output/ Explanation:

Enter any Number153

153  is Armstrong Number

>>> 

========================

Enter any Number123

123  is not Armstrong Number

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad