HANDLING USER INPUT
Python enables you to read user input from the command line via the input() function or the raw_input() function. Typically you assign user input to a variable, which will contain all characters that users enter from the keyboard. User input terminates when users press the <return> key (which is included with the input characters). Listing A.11 displays the contents of UserInput1.py that prompts users for their name and then uses interpolation to display a response.
Listing A.11: UserInput1.py
userInput = input("Enter your name: ")
print ("Hello %s, my name is Python" % userInput)
The output of Listing A.11 is here (assume that the user entered the word Dave):
Hello Dave, my name is Python
The print() statement in Listing A.11 uses string interpolation via %s, which substitutes the value of the variable after the % symbol. This functionality is obviously useful when you want to specify something that is determined at runtime.
User input...