Articles

Program to check armstrong number in python

Program to check armstrong number in python


In this python programming guide, we are going to learn

  • program to check armstrong number in python

Python program to check armstrong number using while loop

The python program to check armstrong number is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

num = int(input("Enter a number: "))
temp = num
sum=0

while temp > 0:
   digit = temp % 10
   sum += digit ** 3
   temp //= 10

if num == sum:
    print("The number is an Armstrong Number!")
else:
    print("The number is not an Armstrong Number!")

The output of python program to check armstrong number is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a number: 153
The number is an Armstrong Number!

Few important tips about this program

1. An Armstrong number is a number such that the sum of its digits raised to the third power is equal to the number itself.

2. Here we break a number digitwise and find its cube and then add all of them up.

3. Finally, we print the answer on the terminal.

 

Snapshot for python program to check armstrong number using while loop:

python program to check armstrong number using while loop

 


Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :    Published Date : Dec 30,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!