def write_real_numbers_to_file():
numbers = []while True:
number = float(input("请输入实数(以-1结束):"))
if number == -1:
break
numbers.append(number)
with open("real_numbers.txt", "w") as file:
for number in numbers:
file.write(str(number) + "\n")
上面是一个示例程序,它提示用户输入若干个实数,直到用户输入-1为止。然后将这些数字写入文件real_numbers.txt中,并且每个数字占一行。