Answer to Question #245117 in Python for Raju

Question #245117

Armstrong numbers between two intervals

Write a program to print all the Armstrong numbers in the given range A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digits.


1
Expert's answer
2021-10-02T07:54:00-0400
A=int(input())
B=int(input())


for i in range(A, B+1):
   x = len(str(i))
   sum1 = 0
   temp = i
   while temp > 0:
       digit = temp % 10
       sum1 += digit ** x
       temp //= 10
   if i == sum1:
       print(i)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS