• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 2. Conditions

Difficulty level:

Task«Automatic sorting»

you & mdash; A junior researcher in the advanced laboratory. Every day you conduct experiments and get sets of numerical data. The analysis protocol requires a different approach depending on the overall result of a series of measurements.

rn

the chief scientific leader established a simple rule: if the sum of all measurements per day is per day It is & nbsp; even & nbsp; in number, this indicates the stability of the process, and the data must be analyzed in order & nbsp; increasing . If the amount & nbsp; is odd , this may indicate an anomaly, and to identify emissions, the largest values ​​need to be studied first of all, that is, to sort data on & nbsp; decrease .

rn = "PT-2"> Your task & mdash; Write a program that automates this primary stage of data sorting.

rn

The program must take a line containing integers separated by spaces. It is necessary to determine whether the sum of these numbers is even or odd. ��TYST ACTION OF THE ANSITUTION, the program must derive these numbers, sorted by increasing. If odd & mdash; by descending.

Input format

A set of experimental data (a line of integers separated by a gap).

Output format

Sorted data set (line of integers separated by a gap).

Example

Input

5 2 8 1

Output

1 2 5 8

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution
# Считываем строку, разделяем её по пробелам и преобразуем каждый элемент в целое число,
# создавая таким образом список чисел.
data = [int(s) for s in input().split()]

# Вычисляем сумму всех чисел в списке.
total_sum = sum(data)

# Проверяем, является ли сумма четной (остаток от деления на 2 равен 0).
if total_sum % 2 == 0:
    # Если сумма четная, сортируем список по возрастанию.
    data.sort()
else:
    # Если сумма нечетная, сортируем список по убыванию.
    data.sort(reverse=True)

# Выводим элементы списка через пробел. Звездочка (*) перед data "распаковывает"
# список, передавая его элементы в print как отдельные аргументы.
print(*data)

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!