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

Python
Дано двузначное число. Определить:
а) является ли сумма его цифр двузначным числом;
б) больше ли числа а сумма его цифр.

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

Ответил asilvejstruk
0

a(

def is_sum_two_digit(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 digits

   sum_of_digits = first_digit + second_digit

   # Check if the sum is a two-digit number

   if sum_of_digits >= 10:

       return True

   else:

       return False

# Test the function

print(is_sum_two_digit(12))  # True

print(is_sum_two_digit(34))  # False

print(is_sum_two_digit(99))  # True

б(

def is_sum_greater_than_a(number, a):

   # 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 digits

   sum_of_digits = first_digit + second_digit

   # Check if the sum is greater than a

   if sum_of_digits > a:

       return True

   else:

       return False

# Test the function

print(is_sum_greater_than_a(12, 3))  # True

print(is_sum_greater_than_a(34, 5))  # False

print(is_sum_greater_than_a(99, 9))  # True

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