Daffodil number" means a three-digit number whose sum of the cubes of the digits is equal to the number itself. Write a python program to ask the user to input a three-digit positive integer n. If n is a "daffodil number", print "YES", otherwise, print "NO".
Answers
Answered by
0
Explanation:
The program for Daffodil number algorithm is written below in python language;
Code :
n = input ("Please enter a three digit number: ")
if ( len(n)!=3 ):
print("The number entered in not valid")
else:
try:
power = [int(i)**3 for i in n]
power_sum = sum(power)
if (int(n) == power_sum):
print("YES")
else:
print("NO")
except:
print("Only digits are to be entered")
Similar questions