• 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
  • к

Занятие 5. While cycle

Difficulty level:

Task«Check on the palindrome»

you & mdash; Cybersecurity specialist, and your goal & mdash; Connect to the secret server "Centaur". The connection protocol is unusual: the server sends you a line-call, and you must immediately send in response the correct password-circuit. If the response is incorrect, the connection is immediately broken.

rn

The response rule is the following: it is necessary to extract all the numbers and all Latin letters from the line, ignoring the rest of the characters. Then you need to make a new line, where all the extracted numbers (maintaining their initial order), and then & mdash, go; All extracted letters (also preserving their order).

rn

your program must read the lines-call until it receives the command & nbsp; session_end . There is no need to bring anything to this team, the program should simply complete its work.

Input format

The input is supplied to the sequence of lines, each on a new line. Each line & mdash; This is another call from the server. The last line will always be & nbsp; session_end .

Output format

For each line-Zavzov (except for & nbsp; session_end ), it is necessary to remove the generated password-circuit on a separate line.

Example

Input

alpha123bravo
call-Sign: 9-x-ray-8
--20-Victor-24--
Session_end

Output

123LPHABRAVO
98Callsignxray
2024victor

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
# Бесконечный цикл, который будет прерван изнутри
while True:
    # Читаем очередную строку-вызов от сервера
    challenge_string = input()

    # Проверяем условие выхода из цикла
    if challenge_string == "SESSION_END":
        break  # Завершаем цикл и программу

    # Создаем две пустые строки для сбора цифр и букв
    digits_part = ""
    letters_part = ""

    # Перебираем каждый символ в полученной строке-вызове
    for char in challenge_string:
        # Если символ является цифрой, добавляем его в строку для цифр
        if char.isdigit():
            digits_part += char
        # Иначе, если символ является буквой, добавляем его в строку для букв
        elif char.isalpha():
            letters_part += char
        # Все остальные символы (пробелы, знаки препинания и т.д.) игнорируются

    # Соединяем две части, чтобы получить финальный пароль-отклик
    response_password = digits_part + letters_part

    # Выводим результат
    print(response_password)

🎉 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, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!