In Python and many other programming languages you can get user input. Do not worry, you do not need to write a keyboard driver.
The input() function will ask keyboard input from the user. If you are still using Python 2, you have the function raw_input().
Related course: Complete Python Bootcamp: Go from zero to hero in Python
The input function prompts text if a parameter is given. The functions reads input from the keyboard, converts it to a string and removes the newline (Enter).
Type and experiment with the script below (save as key.py)
Output should be something like this, depending on your terminal:
By the time you are reading this, perhaps you are used to voice input or other types of human-computer interaction. Eitherway keyboard input is still very useful for coding.
Try these exercises:
- Make a program that asks a phone number.
- Make a program that asks the users preferred programming language.
After completing these continue with the next exercise.