Answer to Question #225225 in Python for Hari nadh babu

Question #225225
A = int(input())
B = int(input())

for num in range(A, B + 1):
   # order of number
   order = len(str(num))
  
   # initialize sum
   sum = 0
   temp = num
   while temp > 0:
       digit = temp % 10
       sum += digit ** order
       temp //= 10
   if num == sum:
       print(num)

In this python program it has two test cases, in this two test cases one test case was getting expected output and second test case are not getting expected output. Please give me expexted output for two test cases. Thank you !


Hints:

  • Use the end operator to print all the Armstrong numbers in a single line.
  • If there is no Armstrong numbers between the given range A to B(including A and B) print -1


Sample Input 1

150

200

Sample Output 1

153

Sample Input 2

1

3

Sample Output 2

1 2 3



1
Expert's answer
2021-08-16T01:03:45-0400
import math

a = int(input())
b = int(input())

for i in range(a, b+1):
    ln = len(str(i))
    s = 0
    for j in str(i):
        s += pow(int(j), ln)
    if s == i:
        print(i, end=" ")
        
print() 

Sample Input 1
150
200
Sample Output 1
153

Sample Input 2
1
3
Sample Output 2
1 2 3

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