python编写一个程序将输入的内容保存到txt文件中,用到while循环。每次输入的内容都要占一行。这个怎么写

如题所述

第1个回答  2017-04-19
with open('1.txt', 'a+') as f:
    print('Input is starting, press q to quit.')
    loop = True
    while loop:
        input_string = input('please input something')
        if input_string != 'q':
            f.write(input_string + '\n')
        else:
            loop = False

本回答被提问者和网友采纳
相似回答