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

Занятие 4. Lines

Difficulty level:

Task«Words without beginning and end»

you & mdash; A data processing specialist in a company who is engaged in optimizing textual information for quick transmission through encrypted channels. You are instructed to implement a program working on the new protocol "Reduction". The essence of the protocol is to shorten the messages, deleting the first and last symbols in each word. This not only reduces the amount of data, but also makes the message unreadable for prying eyes.

rn

your task & mdash; Write a program that accepts the line (message) to the input and processes it according to the “Reduction” protocol.

rn

technical requirements:

rn rn
  • the program must request the user input of the same line of the text.
  • rn
  • The line should be divided into words. The words are considered to be symbols separated by one or more gaps.
  • rn
  • for each word in the line, it is necessary to remove the first and last symbols.
  • rn
  • Processed words should be displayed into one line separated by one gap.
  • rn
  • rn

    Input format

    The initial message for processing (Type of data: line / string). It may contain letters, numbers, punctuation marks and a different number of gaps between words.

    Output format

    Processed message (data type: line / string), where the first and last symbols are removed in each word. The words are separated by one gap.

    Example

    Input

    To show how to work with lines

    Output

    Tob rendering ak abot on troka

    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
    # Запрашиваем у пользователя исходную строку для обработки.
    input_string = input()
    
    # Разбиваем введенную строку на список слов. Метод split() автоматически пробелы между словами.
    words = input_string.split()
    
    # Создаем пустой список, в который будем добавлять обработанные слова.
    result_words = []
    
    # Начинаем цикл for, который перебирает каждое слово из списка words.
    for word in words:
      # Проверяем, что длина слова строго больше 2 символов.
      # Это необходимо, так как удалять первый и последний символ можно только у слов, где есть что удалять.
      if len(word) > 2:
        # Если условие истинно, то мы "срезаем" слово.
        # срез [1:-1] берет все символы, начиная со второго (индекс 1) и заканчивая предпоследним.
        # Затем добавляем укороченное слово в наш список результатов.
        result_words.append(word[1:-1])
    
    # Соединяем слова из списка result_words обратно в одну строку.
    # В качестве разделителя между словами используем один пробел " ".
    output_string = " ".join(result_words)
    
    # Выводим итоговую строку на экран.
    print(output_string)

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