Basic python program to find Armstrong number in an interval using while loop. In this program we can execute the armstrong number program using while loop for beginners.
While Loop in Python
A “While” Loop is used to repeatedly run a block of code until a condition is met. While allows you to repeat a statement until a specified expression is false. The difference between a for loop and a while loop is that in a for loop, the number of iterations to be performed is already known and is used to obtain a specific result, whereas in a while loop, the command runs until a condition is met and the statement is proven to be false.
Armstrong Number Definition
The sum of the cubes of its own digits is equal to an Armstrong number, also known as a narcissistic number. In number theory, a narcissistic number is a number that is the sum of its own digits each raised to the power of the number of digits in a given number base b.
Python Program to Find Armstrong Number in an Interval Using While Loop
lower = 100 upper = 400 for num in range(lower, upper + 1): order = len(str(num)) sum = 0 temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 if num == sum: print(num)