DAS_2024_1/zhimolostnova_anna_lab_2/second_app/app.py

27 lines
898 B
Python
Raw Normal View History

2024-09-21 16:11:07 +04:00
import os
def find_smallest_number_and_cube(input_file, output_file):
# Проверка, существует ли файл data.txt
if not os.path.exists(input_file):
print(f"File {input_file} does not exist.")
return
# Чтение чисел из файла
with open(input_file, 'r') as f:
numbers = [int(line.strip()) for line in f.readlines()]
if numbers:
smallest_number = min(numbers)
result = smallest_number ** 3
# Запись результата в result.txt
with open(output_file, 'w') as f_out:
f_out.write(str(result))
print(f"Saved the cube of the smallest number {smallest_number} to {output_file}")
else:
print(f"No numbers found in {input_file}")
if __name__ == "__main__":
find_smallest_number_and_cube('/var/result/data.txt', '/var/result/result.txt')