LEARN · PREDICT · VERIFY

Guided Instruction

Explore how the input() function receives information and stores it in a variable.

Step 1 – Observe the program

name = input("Enter your name: ")
print("Welcome", name)

Read both statements carefully. Notice that the first statement receives information, while the second statement displays information.

Step 2 – Understand each part

ComponentExplanation
nameA variable that stores the information entered by the user.
=The assignment operator. It assigns the value received from input() to the variable.
input()A Python function that displays a prompt and waits for the user to enter information.
"Enter your name: "The prompt displayed to guide the user. It tells the user what information to enter.
User responseThe information typed by the user after the prompt appears.

Step 3 – Understand the sequence

  1. Python displays the prompt: Enter your name:.
  2. The program pauses and waits for the user to enter a response.
  3. The user types a name and presses Enter.
  4. The input() function returns the entered information.
  5. The assignment operator stores that response in the variable name.
  6. The print() statement displays the welcome message using the stored value.
Important concept: The input() function returns the information entered by the user as a string, even when the user types digits.

Step 4 – Predict before execution

Think about your answers before the teacher runs the program in Python IDLE.

Step 5 – Verify an AI-generated claim

“The text inside the brackets of input() is the information entered by the user.”

Work out whether this claim is correct. Verify it by observing the program in Python IDLE.

  1. Identify the prompt displayed by Python.
  2. Identify what the user types.
  3. Explain the difference between the prompt and the user’s response.

Teacher consolidation: The text inside the brackets is the prompt. The user’s response is entered after the prompt appears and is returned by input().