我想制作一个程序,允许用户连续输入一组三项,每个输入提示一个,然后将这三个值输出到文本文件中的一行。
这是一些基本的例子
text_file = open("filename", "w")
While True:
Code = input("Enter code")
Description = input("Enter description")
Price = input("Enter price")
谁能帮帮我?
编辑: 这就是我到目前为止的情况。
text_file = open("file.txt", "w")
while True:
user_input = input("Enter a code, description and price")
split = user_input.split(" ")
split = str(split)
text_file.write(split)
唯一的问题是它不让我输出列表。
请您参考如下方法:
sep = ',' # separator character
textfile.write(sep.join([Code, Description, Price]) + '\n')
