Getting input from the user

[vocab] user input

M. Lim
Intro to Programming
2 min readJan 17, 2018

--

→ Lab Assignment: “Madlib (User Inputs)” on repl.it

[python learned]

  • input() function
  • .capitalize() method

[demo]

Using keyboard input

User input is information given to a program by the user. Every program has some sort of user interaction, from getting a character’s name for a game to asking for a password to log into an account.

We’ll be focusing on user inputs from the keyboard, but that’s not the only kind there is (also: swiping on a touchscreen, mouse click, voice, etc).

1. Search for “IDLE” in the Start Menu & click to open it.

IDLE is a development environment for Python. It has two main window types, the Shell window and the Editor window. For this example, we will be using the Editor window.

2. To open the Editor window, click: [File → New File]

3. In the new window, type the following code:

name = input("What is your name? ")print("Hi, " + name.capitalize())

4. Now save the file: [File → Save]. You can name it “hi.py”

5. After saving, click [Run → Run Module] to run the program.

Sources: MadLibs, WikiBooks

--

--