Instagram
youtube
Facebook
  • 2 years, 2 months ago
  • 953 Views

Python Program to Check Armstrong Number

Mradul Mishra
Table of Contents

In this tutorial we will learn about how to check armstrong number.  A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself.

  

  •  A number is thought of as an Armstrong number if the sum of its own digits raised to the power number of digits gives the number itself.
  • For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers and, 1634, 8208, 9474 are four-digit Armstrong numbers and there are many more.
  • Armstrong Number
num = int(input())
len_num = len(str(num))
sum = 0
for i in str(num):
    a = pow(int(i), len_num)
    sum = sum + a

if sum == num:
    print("This is armstrong number ", sum)
else:
    print("This is not an armstrong number ", num)

Program to Find Armstrong Number in an Interval

num = int(input())


for j in range(num):
    sum = 0
    len_num = len(str(j))
    for i in str(j):
        a = pow(int(i), len_num)
        sum = sum + a
    if sum == num:
        print("This is armstrong number ", sum)
    else:
        print("This is not an armstrong number ", num)

 

Add a comment: