How to get user input repeatly until i want to qui

2019-02-21 06:06发布

问题:

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;