Develop a Python program to check a given number is Armstrong number or not. A
'n' digit number is called an Armstrong number if the sum of 'n' power of its digits is
equal to the number itself. For example, 407 is an Armstrong number since
4**3+0**3+7**3=407.the powers of their digits (a finite sequence) are
called Armstrong numbers or plus perfect number and are given by 1, 2, 3, 4, 5, 6,
7, 8, 9, 153, 370, 371, 407 etc.
I
Answers
Answer:
Check Armstrong number (for 3 digits)
# take input from the user
num = int(input("Enter a number: "))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Check Armstrong number of n digits
num = input ()
# Changed num variable to string,
# and calculated the length (number of digits)
order = 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 ** order
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Answer:
hello
Explanation:
#Python program to check a given number is Armstrong number or not.
n=int(input("enter a number"))
a=n
sum=0
while n>0:
rem=n%10
sum+=rem**3
n=n//10
if sum==a:
print("its an armsrtong number")
else:
print("its not an armstromg number")