Python Program to check Armstrong number

Python Program for Finding Armstrong Number

Python Program for Finding Armstrong Number. A number is termed Armstrong number if it’s up to the total of the cubes of its own digits.

Lets take an Example:

153 = (1*1*1) + (5*5*5) + (3*3*3) = 153
1634 = (1*1*1*1) + (6*6*6*6) + (3*3*3*3) + (4*4*4*4) = 1634

In the above 153 and 1634 is Armstrong number because it digit cubes is total of itself.

To understand this example, you should have knowledge of following Python programming topics:

Source Code For Finding Armstrong Number of n digits in Python

# Armstrong Number in Python

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

n = len(str(num))
  
while temp > 0:
    digit = temp % 10
    sum += digit ** n
    temp //= 10
if sum == num:
    print(num,'is Armstrong Number')
else:
    print(num,'is not Armstrong Number')

It’s also available on GitHub – https://github.com/studygyaan/python-tutorial/blob/master/Python-Armstrong.py


Warning: mysqli_query(): (HY000/1021): Disk full (/dev/shm/#sql_5a0_0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device") in /home/u862442310/domains/studygyaan.com/public_html/wp-includes/wp-db.php on line 2024
«

Warning: mysqli_query(): (HY000/1021): Disk full (/dev/shm/#sql_5a0_0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device") in /home/u862442310/domains/studygyaan.com/public_html/wp-includes/wp-db.php on line 2024
» 

Leave a Reply

Your email address will not be published. Required fields are marked *