133k views
1 vote
write a program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 7**3 1**3

User Lior Dahan
by
6.1k points

1 Answer

3 votes

Answer:

Written in Python

userinp = int(input("Input: "))

strinp = str(userinp)

total = 0

for i in range(0, len(strinp)):

total = total + int(strinp[i])**3

if userinp == total:

print("True")

else:

print("False")

Step-by-step explanation:

This line prompts user for input

userinp = int(input("Input: "))

This line converts user input to string

strinp = str(userinp)

This line initializes total to 0

total = 0

The following iteration sums the cube of each digit

for i in range(0, len(strinp)):

total = total + int(strinp[i])**3

This if statement checks if the sum of the cube is equal to the user input

if userinp == total:

print("True") This is executed if true

else:

print("False") This is executed if false

User Shankar Panda
by
6.0k points