DAS_2024_1/rogashova_ekaterina_lab_2/worker-2/findnumber.py
2024-10-20 21:59:10 +04:00

30 lines
879 B
Python

import os
def find_max_number(file_path):
max_number = float('-inf')
with open(file_path, "r") as f:
# Читаем все строки из файла
content = f.read()
# Разделяем строки по пробелам для получения списка чисел
numbers = map(int, content.split())
for number in numbers:
if number > max_number:
max_number = number
return max_number
def save_result(result, file_path):
with open(file_path, "w") as f:
f.write(str(result))
def print_result(result):
print("Квадрат наибольшего числа:", result)
file_path = "/var/result/data.txt"
max_number = find_max_number(file_path)
result_file_path = "/var/result/result.txt"
save_result(max_number ** 2, result_file_path)
print_result(max_number ** 2)