Write a Python Program to Check Armstrong Number?

Write a Python Program to Check Armstrong Number?

Armstrong Number:

It is a number that is equal to the sum of its own digits, each raised to a power equal to the number of digits in the number.

For example, let's consider the number 153:
It has three digits (1, 5, and 3).
If we calculate
1 3+ 5 3 + 33, we get1+125+27, which is equal to.

So, 153 is an Armstrong number because it equals the sum of its digits raised to the power of the number of digits in the number.
Another example is 9474:
It has four digits (9, 4, 7, and 4).
If we calculate 9 4 + 4 4 + 7 4 + 4 4,we get 6561+256+2401+256 , which is also equal to 9474

Therefore, 9474 is an Armstrong number as well.
Program
```def myfun():
num=int(input("Enter a number: "))

# Calculate the number of digits in num
num_str=str(num)
num_digits=len(num_str)

# Initialize variables
sum_of_powers=0
temp_num=num

# Calculate the sum of digits raised to the power of num_digits
while(temp_num>0):
digit=temp_num%10
sum_of_powers = sum_of_powers + digit ** num_digits
temp_num = temp_num // 10

# Check if it's an Armstrong number
if(sum_of_powers==num):
print(f"{num}, is an Armstrong number.")
else:
print(f"{num}, is not an Armstrong number.")
if __name__=="__main__":
myfun()

```

Output:

Enter a number: 9474
9474, is an Armstrong number.

Enter a number: 153
153, is an Armstrong number.