From abecc37deb88b8ebc263461a204ef9911f4b4c87 Mon Sep 17 00:00:00 2001 From: Ardor Date: Thu, 7 May 2026 13:24:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20sav?= =?UTF-8?q?e=5Freport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zadanie_1.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/zadanie_1.py b/zadanie_1.py index 8ad37ab..5d74f1c 100644 --- a/zadanie_1.py +++ b/zadanie_1.py @@ -134,4 +134,19 @@ def generate_report(stats: dict) -> str: report_lines.append(f" - {item}") report_lines.append("=" * 50) - return "\n".join(report_lines) \ No newline at end of file + return "\n".join(report_lines) + + +# 10. Сохранение отчета в файл +def save_report(filepath: str, report_text: str) -> bool: + """ + Сохраняет отчет в файл. Возвращает True при успехе. + """ + try: + os.makedirs(os.path.dirname(filepath), exist_ok=True) + with open(filepath, 'w', encoding='utf-8') as file: + file.write(report_text) + return True + except Exception as e: + print(f"Ошибка при сохранении отчета: {e}") + return False \ No newline at end of file