26 lines
798 B
Python
26 lines
798 B
Python
|
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()
|