Armstrong Number

What is an Armstrong number ?

A number equal to sum of the power of 3 of its digits. ( for 3 digit number )
A number equal to sum of the power of 4 of its digits. ( for 4 digit number )

A number equal to sum of the power of n of its digits. ( for n digit number )


Example :
153=13 + 53 + 33
So 153 is an Armstrong number

3 digit Armstrong number

Ask user to enter a 3 digit number and then display if it is an Armstrong number or not.
n=input(" Enter one three digit number ")
sum=0
for i in range(0,len(n)):
  sum=sum+pow(int(n[i]),3)

print("Sum of cube of digits  : ",sum)
if(sum==int(n)):
  print("This is an Armstrong number : ", n)
else:
  print("This is an NOT an Armstrong number : ", n)
Ask the user to enter any number and then display it is an Armstrong number or not.
n=input(" Enter any number more than 9  ")
sum=0
k=len(n)
for i in range(0,k):
  sum=sum+pow(int(n[i]),k)

print("Sum of cube of digits  : ",sum)
if(sum==int(n)):
  print("This is an Armstrong number : ", n)
else:
  print("This is an NOT an Armstrong number : ", n)
List all the Armstrong numbers less than 10000 ( increase the upper limit below )
for n in range(10,10000): # increase this range to get more numbers
 sum=0
 my_str=str(n)
 k=len(my_str)
 for i in range(0,k):
   sum=sum+pow(int(my_str[i]),k)

  #print("Sum of cube of digits  : ",sum)
 if(sum==n):
   print("This is an Armstrong number : ", n)

All Sample codes Strong Number


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer