0
0
Pythonprogramming~10 mins

Taking input using input() in Python - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Taking input using input()
Start Program
Call input()
Wait for user to type
User presses Enter
input() returns string
Store input in variable
Use input value
End Program
The program pauses to get text from the user, then stores it as a string for later use.
Execution Sample
Python
name = input("Enter your name: ")
print("Hello, " + name + "!")
This code asks the user for their name and then greets them.
Execution Table
StepActionInput/OutputVariable 'name' ValueNotes
1Call input() with promptDisplays: Enter your name: '' (empty)Program waits for user input
2User types 'Alice' and presses EnterUser input: Alice'' (still empty)input() is reading user input
3input() returns 'Alice'Returns: 'Alice''Alice'input() call finishes
4Assign returned value to 'name'No output'Alice'Variable 'name' now holds 'Alice'
5Execute print statementOutputs: Hello, Alice!'Alice'Program prints greeting
6Program endsNo output'Alice'No more code to run
💡 Program ends after printing greeting.
Variable Tracker
VariableStartAfter input()After assignmentFinal
name'' (empty)'Alice''Alice''Alice'
Key Moments - 3 Insights
Why does the program wait after calling input()?
Because input() pauses the program to let the user type something. This is shown in execution_table step 1 and 2 where the program waits and reads user input.
What type of data does input() return?
input() always returns a string, even if the user types numbers. This is clear in step 3 where input() returns 'Alice' as a string.
When does the variable 'name' get its value?
The variable 'name' gets the value right after input() returns, at step 4 when the returned string is assigned to 'name'.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of 'name' immediately after input() returns?
A'' (empty string)
B'Alice'
CNone
DThe prompt text
💡 Hint
Check step 3 and 4 in the execution_table to see when 'name' changes.
At which step does the program display the prompt 'Enter your name:'?
AStep 4
BStep 2
CStep 1
DStep 5
💡 Hint
Look at the 'Input/Output' column in the execution_table for the prompt display.
If the user typed 'Bob' instead of 'Alice', how would the variable_tracker change?
AThe 'name' variable would be 'Bob' after assignment
BThe 'name' variable would be 'Alice' regardless
CThe 'name' variable would be empty
DThe program would crash
💡 Hint
Variable_tracker shows the value assigned after input; changing input changes the assigned value.
Concept Snapshot
input(prompt) pauses program and shows prompt
User types text and presses Enter
input() returns the typed text as a string
Assign returned string to a variable
Use variable later in program
Always returns string, convert if needed
Full Transcript
This program starts by calling input() with a prompt asking the user to enter their name. The program pauses and waits for the user to type something and press Enter. When the user types 'Alice' and presses Enter, input() returns the string 'Alice'. This string is then assigned to the variable 'name'. Finally, the program prints a greeting using the value stored in 'name'. The program ends after printing. The key points are that input() always returns a string and the program waits for user input before continuing.