28 lines
940 B
Python
28 lines
940 B
Python
|
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')
|