• 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«Data safety»

you work in an IT company that develops a new system of safe messaging "SecureChat". One of the key security requirements is to mask any numerical information in systemic logs and reports to prevent the leakage of confidential data, such as phone numbers, pin-code, orders or financial information.

rn

Your task & mdash; Write a small but important module for this system. This module should take one line of the text (for example, recording from the log-file) and replace all digital characters in it (from 0 to 9) with stars (*). Moreover, all other symbols & mdash; Letters, punctuation marks, gaps, etc. & mdash; should remain unchanged.

rn

to solve this problem, you are allowed to use only the basic designs of the language: input and output of data, cycle & nbsp; for & nbsp; Symbols, conditional operator & nbsp; if -else & nbsp; to check the symbol and operation with lines (concatenation). The use of built -in functions to replace tunes (for example, & nbsp; . Code () ) or regular expressions is prohibited, since the purpose of the task is & mdash; Work out exactly cycles and conditions.

Input format

One line of the text that can contain any combination of letters (Latin and �irillic), numbers, spaces and special characters (String).

Output format

A changed line, in which all numbers are replaced by stars, and the rest of the characters are saved in their places (String).

Example

Input

Application #791-345 from the client with ID 880215. Urgently process until 18:00.

Output

Application #***-*** from the client with ID ****** ۰ Urgently process until **: **.

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()

# Создаем пустую строку, в которую будем записывать результат.
# Мы не можем изменять исходную строку напрямую, поэтому создаем новую.
result_string = ""

# Начинаем цикл, который перебирает каждый символ (char) во входной строке (input_string).
for char in input_string:
    # Проверяем, является ли текущий символ цифрой, используя метод isdigit().
    # Этот метод возвращает True, если все символы в строке являются цифрами, и False в противном случае.
    # Так как мы проверяем по одному символу, это работает идеально.
    if char.isdigit():
        # Если это цифра, добавляем в результируючую строку звездочку.
        result_string += "*"
    else:
        # Если это любой другой символ (буква, пробел, знак препинания и т.д.),
        # добавляем его в результирующую строку без изменений.
        result_string += char

# После того как цикл завершился и все символы были обработаны,
# выводим на экран итоговую строку с замаскированными данными.
print(result_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, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!