Tuesday, July 28, 2020

Write a Program to Check Armstrong Number in Python.

Armstrong Number in Python.

Armstrong number is a number such that the sum ! of its digits raised to the third power is equal to the number ! itself. For example, 153 is an Armstrong number.

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


OUTPUT

Enter a number ::153
153 is an Armstrong number >

No comments:

Post a Comment

Please do not any spam link in Comment Box