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 an 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
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    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 FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer