My Project - Video Waker Alarm
Get Video alarm on Google Play

Python Armstrong code program


Python Armstrong number check code . But before getting into the code, go through this introduction of Armstrong number. What is an Armstrong number? If the sum of the number of their own digits to the power of the number of digits is equal to that number then that number is called as Armstrong number.

For example : let number be 370 then 370 is of 3 digit number. so if 3^3 + 7^3 + 0^3 = 370 then the number is called as Armstrong number. All one digit number are Armstrong number i.e 1,2,3,4,5,6,7,8,9. Their exist no 2 digit number which is Armstrong number.

For 3 digit 153, 370, 371 and 407 and For 4 digit 1634, 8208 and 9474 are the example of Armstrong number.

Python armstrong number

Here is the Generalized form of finding or checking whether the given number is Armstrong number or not. This python Armstrong program can check for any number of digit. You can also refer to other Armstrong number code of different programming languages. Also see other python programs.

Python Armstrong Code

print('!* To Find Python Armstrong Number')
def Armstrong_Number():
    num = input('Enter Number to check for Armstrong')
    digit = input('Your Entered number is of how many digits')
    f = num
    sum = 0
    while(f!=0):
        a = f % 10
        f = f / 10
        sum = sum + ( a ** digit)
        
    if( sum == num):
        print('%d is a armstrong number' %num)
    else:
        print('%d is not a armstrong number' %num)

Output :

!* To Find Python Armstrong Number

>>> Armstrong_Number()
Enter Number to check for Armstrong153
Your Entered number is of how many digits3
153 is a armstrong number

>>> Armstrong_Number()
Enter Number to check for Armstrong121
Your Entered number is of how many digits3
121 is not a armstrong number
>>>