Вопрос задан 05.12.2023 в 06:53. Предмет Информатика. Спрашивает Каландарова Ангелина.

Даётся возраст 3 ребят: Антона, Бориса и Виктора. Определить, кто из них старше.Формат входных

данных:Строка, содержащая 3 целых числа, разделённых пробелом.Формат выходных данных:Вывести имя самого старшего. Если двое старше одного вывести имямладшего. Если все одного возраста, вывести «Same age»язык python!!
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Кожабаев Канагат.

Ответ:

x = input().split(' ')

x = list(map(int, x))

if x[0] == x[1] == x[2]:

   print('Same age')

elif x[0] == x[1] or x[0] == x[2] or x[1] == x[2]:

   print(min(x))

else:

   print(max(x))

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Task Description

You have been given the ages of 3 children: Anton, Boris, and Victor. Your task is to determine who among them is the oldest. The input is a string containing 3 integers separated by a space, and the output should be the name of the oldest child. If two children are the oldest, you should output the name of the youngest among them. If all three children are the same age, you should output "Same age". You should write the code in Python.

Python Solution

Here's a Python solution to solve the given task:

```python def find_oldest_child(ages): names = ['Anton', 'Boris', 'Victor'] ages = list(map(int, ages.split())) max_age = max(ages) oldest_children = [name for name, age in zip(names, ages) if age == max_age] if len(oldest_children) == 1: return oldest_children[0] else: return min(oldest_children, key=names.index)

# Example usage input_ages = "5 7 5" result = find_oldest_child(input_ages) print(result) ```

In this Python code, we define a function `find_oldest_child` that takes a string of ages as input. We then split the input string into a list of integers representing the ages of the children. We find the maximum age and then identify the oldest child or children based on the maximum age. If there is only one oldest child, we return their name. If there are multiple oldest children, we return the name of the youngest among them.

You can test this function with different input ages to verify its correctness.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос