Locked lesson.
About this lesson
Allow the user to interact with your program with raw_input and input.
Exercise files
Download this lesson’s related exercise files.
Getting User Input .docx59.3 KB Getting User Input - Solution.docx
59.6 KB
Quick reference
Getting User Input
There are several ways of getting user input.
When to use
How you get user import depends on the type of user input you plan to receive (strings, integers, etc).
Instructions
We'll look at raw_input(), input() and stdin.
raw_input() has been deprecated for python 3, but it seems to still work:
print(raw_input("Prompt: "))
raw_input converts whatever you type into a string.
To input numbers, use input() and write:
print(input("Enter a number: "))
To input a string in Python 3 the right way, import the sys module and then use stdin:
import sys
print("Prompt: ")
print(sys.stdin.readline())
Hints & tips
- raw_input() # Deprecated for python 3
- input() # input numbers
- stdin #import strings
Lesson notes are only available for subscribers.