DAS_2024_1/dolgov_dmitriy_lab_2/app2/app2.py
2024-10-07 14:09:04 +04:00

27 lines
878 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from math import sqrt
def find_largest_number_and_square():
input_file = "/var/data/data.txt"
output_file = "/var/result/result.txt"
try:
with open(input_file, 'r') as f:
numbers = [float(num.strip()) for num in f]
largest_num = max(numbers)
squared_num = largest_num ** 2
with open(output_file, 'w') as f:
f.write(str(squared_num))
print(f"Наибольшее числовое значение: {largest_num}")
print(f"Результат: {squared_num}")
except FileNotFoundError:
print(f"Ошибка: Файл {input_file} не найден")
except ValueError:
print("Ошибка: В файле содержатся некорректные данные")
if __name__ == "__main__":
find_largest_number_and_square()