Информатика, вопрос задал TARANTULASHEAD , 1 год назад

Как решить эту задачу в PYTHON?
Дано двузначное число. Определить, равен ли квадрат этого числа учетверен-
ной сумме кубов его цифр. Например, для числа 48 ответ положительный, для
числа 52 — отрицательный.

Ответы на вопрос

Ответил asilvejstruk
1

def is_square_quadruple_sum_cubes(number):

   # Convert the number to a string so that we can access its digits

   number_str = str(number)

   # Get the first and second digits

   first_digit = int(number_str[0])

   second_digit = int(number_str[1])

   # Calculate the sum of the cubes of the digits

   sum_cubes = first_digit**3 + second_digit**3

   # Calculate the square of the number

   square = number**2

   # Check if the square is quadruple the sum of the cubes

   if square == 4*sum_cubes:

       return True

   else:

       return False

# Test the function

print(is_square_quadruple_sum_cubes(48))  # True

print(is_square_quadruple_sum_cubes(52))  # False

print(is_square_quadruple_sum_cubes(99))  # False

Новые вопросы