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

Enter any Number153

153  is Armstrong Number

>>> 

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

Enter any Number123

123  is not Armstrong Number

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad