Test if a number is equal to the sum of the cubes of its digits. Find the smallest and largest such numbers.

Test if a number is equal to the sum of the cubes of its digits.
n=input(" Enter a 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("Digits are matching to cube  : ", n)
else:
  print("Digits are NOT matching to cube : ", n)
Output
Enter a number 371
Sum of cube of digits  :  371
Digits are matching to cube  :  371
Find the smallest and largest such numbers.
my_list=[]

for n in range(10,100000): # increase this range
  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]),3)

  if(my_sum==int(n)):
    print("This is a matching number: ",n)  
    my_list.append(n)

print("Highest number : ",max(my_list))
print("Lowest  number : ",min(my_list))
Output
This is an matching number:  153
This is an matching number:  370
This is an matching number:  371
This is an matching number:  407
Highest number :  407
Lowest  number :  153
All Sample codes Strong Number Armstrong Number

Podcast on Python Basics


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







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