while 1:
text_file = open("write_it.txt", "w")
word = input("Please add to a text file: ")
我还需要添加什么才能使我的代码正常运行?
答案 0 :(得分:3)
这应该有效:
text_file = open("write_it.txt", "w")
while 1:
word = input("Please add to a text file: ")
if not word:
break
text_file.write(word)
text_file.close()
答案 1 :(得分:0)
不确定,但内部的那个开放声明不能影响它的行为? 你试过把它移出while循环吗?