Armstrong Number or not - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 19, 2020

Armstrong Number or not

python-mini

Question

To Find whether the number is an Armstrong number or not.

Sample TestCaseExpected Output

Enter a number : 153                                                                    153 is an Armstrong number




Answer


num=int(input("Enter a number :"))
Sum=0
temp=num
while temp>0:
    dig=temp%10
    Sum+=dig**3
    temp//=10
if num==Sum:
    print(num,"is an Armstrong number")
else:
    print(num,"is not an Armstrong number")

No comments:

Post a Comment