Python Program to Print 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.

Input

The first line has an integer A

The second line has an integer B

Output

Print all Armstrong numbers separated by a space.

If there are no Armstrong numbers in the given range, print -1

Sample Input 1

150

200

Sample Output 1

153

Code:

a=int(input())
b=int(input())
flag=False
for i in range(a,b+1):
    i=str(i)
    l=len(i)
    s=0
    for j in range(0,l):
        s=s+(int(str(i[j]))**l)
    if str(s)==str(i):
        k=""
        k=k+str(i)+" "
        flag=True
        print(k,end="")
if not flag:
    print("-1")☝

Comments

Popular posts from this blog

CODING ASSIGNMENT 4

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page