Write a program to check armstrong numbers in certain interval

Write a program to check armstrong numbers in certain interval

Program

def myfun(): 
    lower = int(input("Enter Staring Value : "))
    upper = int(input("Enter Ending Value : "))
    for num in range(lower, upper + 1):
        # order of number
        order = len(str(num))
        sum = 0
        # find the sum of the cube of each digit
        temp = num
        while temp > 0:
            digit = temp % 10
            sum += digit ** order
            temp //= 10

        if num == sum:
            print(num)
             
if __name__=="__main__":
    myfun()



Output:

Enter Staring Value : 1
Enter Ending Value : 2000
1
2
3
4
5
6
7
8
9
153
370
371
407
1634


Input: 120
Output: No
120 is not a Armstrong number.
1*1*1 + 2*2*2 + 0*0*0 = 9

Input: 1253
Output: No
1253 is not a Armstrong Number
1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723

Input: 1634
Output: Yes
1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634


More Questions


30 . Write a program to check armstrong numbers in certain interval
31 . Write a program to merging dictionaries
32 . Write a program to print swapping variables
33 . Write a python program to counting item occurrences
34 . Write a python program to print flatten a nested list
35 . Write a python program to Find the index of the largest number in the list
36 . Write a python program to Find the index of the smallest number in the list
37 . Write a python program to find absolute value of a number in the list
38 . Write a python program to adding a thousand separator
39 . Write a python program startswith and Endswith Methods
40 . Write a python program to print Nlargest numbers



For latest job updates join Telegram Channel: https://t.me/sateeshm