n=input(" Enter one three digit number ")
my_sum=0
for i in range(0,len(n)):
my_sum=my_sum+pow(int(n[i]),3)
print("Sum of cube of digits : ",my_sum)
if(my_sum==int(n)):
print("This is an Armstrong number : ", n)
else:
print("This is an NOT an Armstrong number : ", n)
By using pow() function we can get the power of two input numbers.
n=input(" Enter any number more than 9 ")
my_sum=0
k=len(n)
for i in range(0,k):
my_sum=my_sum+pow(int(n[i]),k)
print("Sum of cube of digits : ",my_sum)
if(my_sum==int(n)):
print("This is an Armstrong number : ", n)
else:
print("This is NOT an Armstrong number : ", n)
for n in range(10,10000): # increase this range to get more numbers
my_sum=0
my_str=str(n)
k=len(my_str)
for i in range(0,k):
my_sum=my_sum+pow(int(my_str[i]),k)
#print("Sum of cube of digits : ",my_sum)
if(my_sum==n):
print("This is an Armstrong number : ", n)
Output
This is an Armstrong number : 153
This is an Armstrong number : 370
This is an Armstrong number : 371
This is an Armstrong number : 407
This is an Armstrong number : 1634
This is an Armstrong number : 8208
This is an Armstrong number : 9474
All Sample codes Strong Number Number equal to cube of its Digits
AUTHOR
🎥 Join me live on YouTubePassionate about coding and teaching, I love sharing practical programming tutorials on PHP, Python, JavaScript, SQL, and web development. With years of experience, my goal is to make learning simple, engaging, and project-oriented. Whether you're a beginner or an experienced developer, I believe learning by doing is the best way to master coding. Let's explore the world of programming together!