In this program, we will make a program to check whether the given number is Armstrong. We will also make a python program to print(or find) Armstrong numbers in an interval.
Armstrong numbers in python: Armstrong number is a number that is the sum of its digits, each raised to the power of the number of digits.

Python Program to Check Armstrong Number using while loop
In this Python program, we will check whether the number entered by the user is an Armstrong number.
num = int(input("Enter a Number:"))
order = len(str(num))
temp = num;
sum = 0
while(temp>0):
digit =temp%10
sum += digit **order
temp = temp//10
if(sum==num):
print("",num,"is an Armstrong number")
else:
print("",num,"is not an Armstrong number")
Enter a Number:371
371 is an Armstrong number
Algorithm:
- Input the number from the user.
- Initialize “order” with the length of the num variable.(order= Number of digits)
- Store the value of the num variable in the temp variable.
- Initialize the sum of digits with zero.
- While temp>0, repeat steps 6-7.
- digit =temp%10 and sum += digit **order
- temp = temp//10
- If the sum equals num, then we will print the number entered by the user as an Armstrong number
Related post: Menu-Driven Program in Python using while loop
Python Program to find Armstrong Number in an Interval.
This program will print Armstrong numbers between intervals according to the lower and upper range. Here, the lower range and upper range are given by the user.
lower = int(input("Enter lower range:"))
upper = int(input("Enter upper range:"))
for num in range(lower,upper+1):
sum = 0
order = len(str(num))
temp = num;
while(temp>0):
digit=temp%10
sum += digit **order
temp = temp//10
if(sum==num):
print(num)
Enter lower range:100
Enter upper range:1000
125
153
216
370
371
407
729
Armstrong Number in Python using for loop
In this program, we will use for loop to complete our task. We will find the unit digit by performing modulus operation between current number and 10. Then add the current number power of the length of the number. If the total sum is equals to the actual number then it is an Armstrong number.
num = int(input("Enter a Number:"))
order = len(str(num))
temp = num;
sum = 0
stnum=str(num)
for i in stnum:
digit =temp%10
sum += digit **order
temp = temp//10
if(sum==num):
print("",num,"is an Armstrong number")
else:
print("",num,"is not an Armstrong number")
Enter a Number:656
656 is not an Armstrong number
This post is all about making a program to check an Armstrong number. I hope this program will run successfully on your device. You should comment below if you have any doubts about this program.
Especially referring For Loop example it throughs me an error on order = len(str(num)), Can you help me out with this.
Hi, it is working properly on programiz compiler. Order means how many digits are there in the number.
You can also use below code to find order of the number.
order = 0
num2 = num
while num2 > 0:
order+=1
num2//=10