Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


Python Program to Print all Armstrong Numbers between 100 to 999 using While Loop


In this example shows, how to print all armstrong numbers between 100 to 999 using while loop.

Steps

The program starts with a while loop takes the last digit of number using the modulus operator, cubes it and adds it to the sum the armstrong numbers.

Example:
Example.py
start = 100
end = 999

for n in range(start, end + 1):

   line = len(str(n))
   sum = 0

   temp = n
   while temp > 0:
       digit = temp % 10
       sum = sum+digit ** line
       temp=temp//10

   if n == sum:
       print(n)

Output

153
370
371
407

Prev Next