Python program to check number is Armstrong or not

Python program to check whether the given number is Armstrong Number or Not

Write a Python program to accept a number from the user, and check whether the given number is Armstrong Number or Not

Video Tutorial

What is the meaning of an Armstrong Number..?

A number is an Armstrong number when the sum of the nth power of each digit is equal to the number itself. Here n is the number of digits in the given number. For example,

Armstrong Number or Not
Armstrong Number or Not

Source code of Python Armstrong program

num = int (input ("Enter the number: "))
temp = num
cnt = 0
while temp > 0:
    cnt = cnt + 1
    temp = temp // 10
    
sum = 0
temp = num
while temp > 0:
    rem = temp % 10
    sum = sum + pow (rem, cnt)
    temp = temp // 10
    
if (num == sum):
    print ("The number", num, "is an Armstrong number")
else:
    print ("The number", num, "is not an armstrong number")

Output:

Case 1:

Enter the number: 123

The number 123 is not an Armstrong number

Case 2:

Enter the number: 1634

The number 1634 is an Armstrong number

Summary:

This tutorial discusses how to write a Python program to verify whether the number is Armstrong. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published.