How to get user input repeatly until i want to quit? [closed]

耗尽温柔 提交于 2019-12-01 13:34:10

问题


I want to get user input for multiple times and store the input data together in a string until input "quit" to quit from input. I think a for loop can work but I don't know how to do it.


回答1:


while True:
    user_input = raw_input("Enter something:")
    if user_input == "quit":
        break



回答2:


Try this:

input_string = ''
while 1:
    input = raw_input('Add to string: ')
    if input == 'quit': break
    input_string += input 



回答3:


while True:
    input = raw_input('Prompt')
    print input
    if (input == 'quit'):
        break;


来源:https://stackoverflow.com/questions/12608654/how-to-get-user-input-repeatly-until-i-want-to-quit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!