codescracker


python

Python Program to Check Armstrong or Not



« Previous Program Next Program »


Check Armstrong or Not in Python

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.

Python Programming Code to Check Armstrong or Not

Following python program ask from user to enter any number to check for Armstrong number:

# Python Program - Check Armstrong Numbers
		
while True:
	print("Enter 'x' for exit.")
	num = input("Enter any number: ")
	if num == 'x':
		break
	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.\n")
		else:
			print(number,"is not an Armstrong Number.\n")

Here is the sample run of the above Python program shows how to check whether a number is an Armstrong number or not:

python check armstrong number

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test