Find the number is Armstrong number or not // python program

First we understand what is Armstrong number :

Armstrong number :

>An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

Input :

>371

Output :

> number is Armstrong

Algorithm :

first we take input from user

then input store in variables

then check the input is Armstrong or not

if condition is True number is Armstrong

if condition is False then number is not Armstrong

a= int(input('one no.:')) # INPUT 
b= int (input("second no.:" )) # INPUT 
c= int(input("third no.:"))  # INPUT 
if a**3 + b**3+c**3==(a*100+b*10+c*1):  # WE CHECK THE CONDITION 
  print("no. is Armstrong")
else:         # IF CONDITIOON FALSE
  print("no. is not Armstrong")

 

Now we use second method to know the the number is Armstrong or not :

We use list method :

n=153
k=n
s= []
while n>0:
  d= n%10
  n=int(n/10)
  s.append(d)      # this is the append method in list 
if k== s[-1]*100+s[-2]*10+s[-3]*1 :   # check the codition if True then number is Armmstrong  
  print(k," n is armstrong no.")

Tags:

python program

check the number is Armstrong or not

Find the number is Armstrong number or not

Armstrong number

Armstrong number program

Armstrong number program in python

 

List of other python program :

Find the number is Armstrong number or not // python program

Python program to Identify Even and Odd Elements in List

Find the Duplicate Elements in the List – Python List Program

Reverse And Invert A Dictionary Mapping In Python

Leave a Comment

%d bloggers like this: