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