In this article, we will see how to check whether a number is armstrong number or not in Python.
What is armstrong number
Armstrong numbers, also called narcissist numbers, are those number whose sum of cube of digit is equal to that number.
How to check whether a number is armstrong
Suppose we are given any number n. (d3d3d1). Here d1 is digit at one’ place, d2 is digit at 10s place and d3 is digit at 100th place.
n = d3^3 + d2^3 + d1^3
Python program to see whether a number is armstrong or not
def checkNarcissist(number): total =  count = len(str(number)) power= int(count) digits = [int(x) for x in str(number)] for i in digits: product = i**power total.append(product) sumtotal=sum(total) if(sumtotal==number): print(str(number)+ " is a narcissist number") else: print(str(number)+ " is not a narcissist number") checkNarcissist(371)
In this article, we have saw how to check armstrong number in Python. If you have any confusion regarding the code, please do comment in discussion thread below or send us email to firstname.lastname@example.org.
You can use our code in your website. Kindly do acknowledge us by linking our website or this page.
- We are offering online courses in technical skills and interview preparation. Do visit Xamnation courses to check complete list of our courses. We are offering live classes, online material and interview series for cracking job interviews. Our famous courses are :
- Online Python Course
- Online Java Course
- Online Machine Learning Course
- Online Data Structure Course
If you are interested, you can reach us at email@example.com for more details.