1) d. Getting user input

If you want to get user’s input the simplest way is to use “input” function.

Try and run the following piece of code.

Code execution will freeze waiting for the user to input something into the terminal. Once the user provides some value and presses the “Enter” key, the code execution will continue.

When you run this code, a user might not know that he is expected to provide an input. To him it might seem like the program has stopped executing.

To make it obvious to the user that he has to enter some value, you can provide an optional (but recommended) argument to the “input” function.


This time the user is prompted to enter a value. Note that if the user just presses the “Enter” key when prompted for input the result will be an empty string.

One unconventional use could be to use the “input” function to provide some time for the user to do something and then to allow him to resume the program. You only wait for the user to press “Enter” and you don’t care what the user actually types into the prompt, so you don’t need to assign the result of the “input” function to a variable.




Thus, you can use the “input” function to get a value from the user. This value may be a character string or a number. By default Python assumes the input value to be a string. Due to this you wouldn’t be able to perform calculations with the entered value.

A note to visitors:

Are you enjoying learning Python? Continue this momentum. Get access to the full course right now!