In Python and many other programming languages you can get user input. Do not worry, you do not need to write a keyboard driver. In Python the input() function will ask keyboard input from the user.
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)
#!/usr/bin/env python3 name = input('What is your name? ') print('Hello ' + name) job = input('What is your job? ') print('Your job is ' + job) num = input('Give me a number? ') print('You said: ' + str(num))
What you see on success
Try these exercises:
1. Make a program that asks a phone number. 2. Make a program that asks the users preferred programming language. 3. What is the difference between Python 2 and Python 3 input?
After completing these continue with the next exercise.
1. Ask phone number
num = input('Give me a number? ') print('You said: ' + str(num))
2. What is your favorite language?
lang = input('What is the best language, C++ or Python? ') print('You said: ' + lang)
3. Difference between Python 3 and Python 2
Python 3 users can simply type input() instead of raw_input().