To check whether given number is an Armstrong number or not an Armstrong number in python, you have to ask from user to enter a number to check for Armstrong number as shown in the program given below.
Following python program ask from user to enter any number to check for Armstrong number:
# Python Program - Check Armstrong Numbers print("Enter 'x' for exit."); num = input("Enter any number to check for armstrong: "); if num == 'x': exit(); else: number = int(num); tot = 0; temp = number; while temp > 0: dig = temp % 10; tot += dig ** 3; temp //= 10; if number == tot: print(number,"is an Armstrong Number."); else: print(number,"is not an Armstrong Number.");
Here is the sample run of the above Python program shows how to check whether a number is an Armstrong number or not:
As you have already learned about armstrong number in previous program, that is, generating armstrong number using python, now let's enter any number and find whether the number is armstrong or not as given in below sample run:
Let's re-run the same program and check for a number who is not an armstrong number say 124:
Below is the same program on python shell:
You may also like to learn or practice the same program in other popular programming languages: