How to Enter Several User Input Strings in Python
Getting user input in Python usually involves using an input function such as "raw_input" and assigning the input to a variable. However, getting multiple, separate lines of input from the user can be a little trickier. The best way to do so is to fashion a loop that feeds input into a list of items. Then, you can set aside a particular input, like a character or number, which signifies that the input has ended.
Instructions
-
-
1
Set aside a variable list to accept user input:
>>>user_input = list()
-
2
Accept a single line of user input using the "raw_input" function, and append it to the list:
>>>user_input.append(raw_input("Input: "))
-
-
3
Set up a "while loop," which will only execute until the user inputs the single letter 'Q':
>>>i = 0
>>>while user_input[i] != 'Q':
. . . user_input.append(raw_input("Input: "))
. . . i += 1
-
1