Quantcast
Channel: The Crazy Programmer
Viewing all articles
Browse latest Browse all 761

Python Program to Check Armstrong Number

$
0
0

Here you will get python program to check armstrong number.

A number is said to be an armstrong number if sum of its digits raised to the power n is equal to itself. Here n is total digits in number.

For example 370 is armstrong number.

Here n = 3, so 33 + 7+ 0= 27 + 343 + 0 = 370

Python Program to Check Armstrong Number

num = int(input("enter a number: "))

length = len(str(num))
sum = 0
temp = num

while(temp != 0):
	sum = sum + ((temp % 10) ** length)
	temp = temp // 10

if sum == num:
	print("armstrong number")
else:
	print("not armstrong number")

Output

enter a number: 370
armstrong number

Comment below if you have any queries related to above program for armstrong number in python.

The post Python Program to Check Armstrong Number appeared first on The Crazy Programmer.


Viewing all articles
Browse latest Browse all 761

Trending Articles