DAS_2024_1/melnikov_igor_lab_2/app.py
2024-12-15 16:56:11 +04:00

28 lines
940 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
def multiply_first_and_last(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:
first_number = numbers[0]
last_number = numbers.pop()
result = first_number * last_number
# Записываем полученный результата в result.txt
with open(output_file, 'w') as f_out:
f_out.write(str(result))
print(f"Saved {first_number}х{last_number} to {output_file}")
else:
print(f"No numbers found in {input_file}")
if __name__ == "__main__":
multiply_first_and_last('/var/result/data.txt', '/var/result/result.txt')