DAS_2024_1/kadyrov_aydar_lab_2/app_two/main.py

26 lines
798 B
Python
Raw Permalink Normal View History

2024-10-24 20:07:47 +04:00
import os
def get_largest_number_from_file(filepath):
with open(filepath, 'r') as f:
numbers = [int(line.strip()) for line in f.readlines()]
return max(numbers)
def save_square_of_number(number, output_filepath):
result = number ** 2
with open(output_filepath, 'w') as f:
f.write(str(result))
def main():
input_filepath = '/var/result/data.txt'
output_filepath = '/var/result/result.txt'
if os.path.exists(input_filepath):
largest_number = get_largest_number_from_file(input_filepath)
save_square_of_number(largest_number, output_filepath)
print(f"Largest number squared: {largest_number}^2 saved to {output_filepath}")
else:
print(f"Input file {input_filepath} not found!")
if __name__ == "__main__":
main()