Reading from the Console
Now that we know the basics about variables, we can ask for input from the user. Use the following line to tell our program to wait until the user types something into the console. Then, the computer takes whatever is typed into the console, and stores it into the variable called value.
value = input()
Here’s and examples of how to use input() to accept user input:
print(`"What's your name?"`) value = input() print(`"Hello"` + value + `"!"`)
Give this a try! When you hit run, you’ll notice that the below image doesn’t appear on the console yet.
This is because the program is waiting for you to type something! Enter your name or ‘Nuvi’ into the console on the right, press Enter, and check that it prints out correctly.
Even if we type in a number, such as 8, the variable value will contain the string "8"
. Be careful when attempting to do math on input variables!