Computer Science, asked by sunainatiwari103, 9 months ago

write python program to print armstrong number from 1to 1000 using function​

Answers

Answered by AdorableMe
114

Question

write python program to print Armstrong number from 1 to 1000 using function​

Source Code

# Program to ask the user for a range and display all Armstrong numbers in that interval

# take input from the user

lower = int(input("1 "))

upper = int(input("1000 "))

for num in range(lower, upper + 1):

  # order of number

  order = len(str(num))

   

  # initialize sum

  sum = 0

   # find the sum of the cube of each digit

 temp = num

  while temp > 0:

      digit = temp % 10

      sum += digit ** 3

      temp //= 10

  if num == sum:

      print(num)

Output

Enter lower range: 1

Enter upper range: 1000

1

153

370

371

407

Additional Info :-

An Armstrong number is a number such that the sum ! of its digits raised to the third power is equal to the number ! itself.

◘ For example,

3³ + 7³ + 1³ = 27 + 343 + 1 = 371

Similar questions