Python Program to Check Armstrong number

[5412 views]



In this article, we will write a simple python program which checks whether a number is Armstrong number or Not.

Program:

##To find whether number is armstrong or not ## Armstromg number is number where sum of cube of each digit in the number is equal to the number. def armstrong(n): sum = 0 while n > 0: ## Loop till n is greater than zero num = n % 10 ## to find the last digit in the number sum = sum + (num * num * num) ## find cube of the last digit add it in sum n = n / 10 ## to find the remaining number except the last number return sum if __name__ == '__main__': num = int(raw_input("Enter a number")) result = armstrong(num) if result == num: print "Armstrong" else: print "Not armstrong"

Output:

Enter a number 153 Armstrong
Similar Post - Algorithm and Flowchart for Armstrong Number
        




Getting any Errors while coding? Ask us on our new Forum:




Liked Article? Please Buy Author a Coffee


Comments



Search
For Sponsored Advertisement OR Freelance Programming Article Submission, Contact us at atechdailyweb@gmail.com
Recommended Deal Ends in











Quizzes:
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Why does everyone hate Java?
How much JavaScript to learn for Web Development
How to Convert EPOCH to Date in Java
Search Tags

    Write a program to Check Armstrong number in python.

    Simple Armstrong number program in Python using while loop