How to Find Armstrong Number in an Interval using Python?


If sum of cubes of individual digits in a number add up to the number itself, it is called armstrong number. for example 153=1**3+5**3+3**3

Example

Following Python program find armstrong numbers between 100 to 1000

for num in range(100,1000):
  temp=num
  sum=0
  while temp>0:
      digit=temp%10
      sum=sum+digit**3
      temp=temp//10
      if sum==num:
           print (num)

Output

The output is as follows −

153
370
371
407


Updated on: 21-Feb-2020

665 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements