How to Find Armstrong Number in an Interval using Python?

PythonServer Side ProgrammingProgramming

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


raja
Published on 25-Feb-2018 18:54:51
Advertisements