liveBook · Manning

Input()

As explained in A Pythonic Adventure: From Python basics to a working web app

The Python input function optionally displays a prompt, waits for user text, and returns the entered text.

input() lets a program pause, ask the user for text, and keep the response. Call it with empty parentheses to wait silently, or pass a prompt so the user knows what to enter. After the user types and presses Enter, input() returns the entered text. section 1.2

Collecting a coffee order

A small coffee-shop program stores each answer in a clearly named variable, then prints the completed order: name = input("Please enter your name: ") drink = input("Please enter your drink: ") flavor = input("Please enter your flavor: ") topping = input("Please enter your topping: ") print("Here is your order, ", name) print("Main product: ", drink) print("Flavor: ", flavor) print("Topping: ", topping) Using separate variables matters: assigning every answer to answer would replace the previous response. The same pattern can place responses into a dictionary, such as order['name'] = input("What's your name: "). section 1.2 section 7.0

Listing 1.1 The first version of the coffee shop application
print("Welcome to Erik's Coffee Shop!")
 
name = input("Please enter your name: ")
drink = input("Please enter your drink: ")
flavor = input("Please enter your flavor: ")
topping = input("Please enter your topping: ")
print("Here is your order, ", name)
print("Main product: ", drink)
print("Flavor: ", flavor)
print("Topping: ", topping)
print("Thanks for your order!")

Run the complete coffee-shop application and compare each prompt with the resulting printed order. section 1.2

How A Pythonic Adventure: From Python basics to a working web app covers it

How deep it goes
Explains prompting, keyboard entry, returned text, variable assignment, and dictionary storage without descending into implementation internals.
Examples
Uses name, drink, flavor, topping, coffee-shop prompts, and a get_order() function as concrete examples.
What it assumes
Assumes basic Python statements while teaching functions, arguments, strings, variables, and dictionaries through guided examples.
What you can do after
Build it from scratch by collecting user text, saving responses, and incorporating them into printed output or dictionaries.
How it connects
Connects input() with functions, arguments, strings, variables, dictionaries, and return values.

Also explained in

Compare how 7 books explain input() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of A Pythonic Adventure: From Python basics to a working web app. The section links point to the parts of the book it draws on.