Python program to print the Armstrong numbers between the two intervals

             

        Python program to print the Armstrong numbers between the two intervals

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153  is an Armstrong

Program:

    # Python program to print the Armstrong numbers between the two intervals

    import math
    n1 = int(input("Enter start value : "))
    n2 = int(input("Enter end value : "))
    result = 0
    n = 0
    for i in range(n1+1 ,n2,1):
        t2 = i
        t1 = i

        while (t1 != 0):
            t1 = int(t1/10)
            n = n + 1

        while (t2 != 0):
            remainder = t2 % 10
            result = result + math.pow(remainder, n)
            t2 = int(t2/10)

        if (result == i):
            print(i)

        n = 0
        result = 0

    OutPut:
    Enter start value : 100
    Enter end value : 500
    153
    370
    371
    407


    Enter start value : 200
    Enter end value : 1000
    370
    371
    407





















    No comments:

    Post a Comment