Materials & Prep
Prepare a projector or board and have students open their programming environment. Display or provide the code examples in the lesson. No special materials are needed.
Opening
Display
print("Team scored", 7, "points") print("Team scored", 10, "points") print("Team scored", 3, "points") print("Team scored", 8, "points")
Ask“What stays the same in all four lines? What changes? If the team scored 12 points next, what exact edit would you make?” Students answer using their existing understanding of copied code and changing values. Confirm that the message and operation stay the same while the number changes.
Connect“You have identified one action with different input values. Instead of copying the action four times, we can write it once and supply the changing value when we use it.” Introduce the term parameter as a named placeholder inside a function. Tell students that the repeated code they have been copying is the problem this tool solves.
Direct instruction
Model
def report_score(points)
print("Team scored", points, "points")
report_score(7) report_score(10) report_score(3) report_score(8)
Think aloud“The lines inside the function are the repeated action, so I write them once. I name the changing piece points in the function definition. Points is the parameter. When I call report_score(7), 7 is the argument that fills the parameter for that call. The output is Team scored 7 points. The next call supplies 10, so the same code produces Team scored 10 points.”
Display the complete result: Team scored 7 points; Team scored 10 points; Team scored 3 points; Team scored 8 points. Emphasize that the function definition does not run until a call is made.
ConfrontA common error is putting the actual value in the definition:
def report_score(7)
print("Team scored", 7, "points")
Explain that Python reports a syntax error because a definition needs a name for the changing value, not a specific value. The actual value belongs in the call: report_score(7). Also point out the indentation under the function definition.
Check for understandingStudents hold up or write D for definition and C for call beside each line: “def report_score(points):” and “report_score(12).” Ask one student to explain what points and 12 each represent.
Guided practice
Display
def show_total(quantity)
price = 3 print("Total:", quantity * price)
show_total(2) show_total(5) show_total(10)
Work through the first call together. Students predict the output before running it: Total: 6. Then predict and run the other calls: Total: 15 and Total: 30. Ask: “Which value changes without changing the function body?”
Have students modify the function so it reports a different fixed item price, then add show_total(0) and explain the result. Circulate and look for a parameter used in the function body, a matching name, correct indentation, and calls outside the definition.
Scaffold: Provide this frame for students who need it
def function_name(parameter)
print("message", parameter)
function_name(value1) function_name(value2)
Students may first replace the bracketed words with concrete names and values before creating their own version. Partners can trace one call by circling the argument and drawing an arrow to the matching parameter.
Independent work
Students convert a repeated-code artifact into a function. They may use their own previous example or this starter: print("Tickets:", 2, "Cost:", 2 * 6) print("Tickets:", 5, "Cost:", 5 * 6) print("Tickets:", 0, "Cost:", 0 * 6) print("Tickets:", 8, "Cost:", 8 * 6)
They write a function named ticket_total with a parameter for the changing number, place the repeated calculation and output inside the function, call it with 2, 5, 0, and 8, and add one new test value. They run the program and compare every output with the original code.
Prompt“What part of your code is the repeated action? Which value changes? Where is that value represented by the parameter?” Students write two sentences beneath the code: “The parameter is . It is useful because .”
ExtensionStudents add a second parameter, such as price, so the same function can calculate different ticket prices. They test ticket_total(3, 6) and ticket_total(3, 8), then explain why this version is more reusable than changing a fixed value inside the function.
Closing
Exit ticketWrite a function named double_value with one parameter. It must print the parameter multiplied by 2. Call it with 4 and 9, then state in one sentence why using a parameter is better than writing a separate copied line for each value.
Expected code
def double_value(number)
print(number * 2)
double_value(4) double_value(9)
Expected output: 8 and 18. Collect the code and explanation. A complete response names a parameter, uses it in the function body, calls the function with different arguments, and connects the parameter to reducing repetition or increasing reuse.