JustCaptain kod-buduschego
llm/intern-0a6a46
Перейти к файлу
Код
kod-buduschego Python 2025-20263.5. Функция enumeratepracticeschatgpttask_1.py
anc update c70a58f 8 октября 2026 г.
task_1.py
"""
1. Найти все ошибки

Дан список логов:


Выведи номера строк (с 1) и текст только для ошибок (ERROR).

Ожидаемый вывод:

2: ERROR Database failed
4: ERROR Invalid password
"""

logs = [
    "INFO Server started",
    "ERROR Database failed",
    "INFO User logged in",
    "ERROR Invalid password",
    "WARNING Disk almost full",
]


def print_logs(logs: list[str], tags: list[str] | None = None) -> None:
    for id, log in enumerate(logs, start=1):
        tag_log: str = log.split(" ")[0]
        if tags is None:
            print("{}: {}".format(id, log))
        elif tag_log in tags:
            print("{}: {}".format(id, log))


if __name__ == "__main__":
    print_logs(logs=logs)