Python Program to Check Armstrong Number – Programming Code Examples
Python

Python Program to Check Armstrong Number3 min read

Armstrong number is a number whose sum of the nth power of digits is equal to the number itself. Where n is called the order, which is equal to the number of digits present in the number.

For example:
Let’s take a number 371, which is an Armstrong number. Let’s see
Order of number 371 (n) = 3
371 = 33 + 73 + 13
Let’s take one more example of number 1634
Order of number 1634 (n) = 4
1634 = 14 + 64 + 34 + 44

Write a program to Check Armstrong Number in Python




Code:

 

Check Armstrong number by taking the number as int datatype

Output:

Check Armstrong number by taking the number as string datatype

The idea is same as above but the program is a little bit short and also the process.

Output:

Check Armstrong number by using recursion

In this, we have created a getSum() recursive function which will return the sum of the nth power of digits of the number. Rest is almost same.

Output:

Leave a Comment