3.12 Calling Procedures
3.12 Calling Procedures
3.12 Calling Procedures
1. Reference Guide
Key Vocabulary & Concept Definitions
| Term | Definition | Example |
|---|---|---|
| Procedure (Function) | A named block of reusable code instructions. | def report_incident(): |
| Parameter | A variable listed in the procedure definition that receives data. | def report_incident(location): |
| Argument | The actual value sent into the procedure during a call. | report_incident("Poway") |
| Decomposition | Breaking a complex program into smaller sub-tasks. | Separating process_report() and is_priority() |
| Helper Procedure | A procedure called inside another procedure to complete a specific sub-task. | is_priority() inside process_report() |
2. LxD Cycle Process
Empathize: Students may understand how to write individual lines of Python code but struggle to organize repeated actions into reusable procedures. They may also confuse parameters with arguments or have difficulty understanding how one procedure can call another.
Define:
- POV: AP CSP students need a clear and practical way to practice defining and calling Python procedures with parameters so they can organize a program into reusable parts.
- Learning Goal: Students will define procedures with parameters, pass argument values into procedures, call procedures, and use helper procedures to break a larger task into smaller parts.
Ideate:
- HMW Question: How might we teach procedural decomposition and argument passing through a realistic emergency-response scenario?
- HMW Question: How might we show that a main function can delegate sub-tasks to smaller helper procedures to keep code readable?
- Activity: Students will build a simplified emergency-response program based on the Poway Neighborhood Emergency Corps. They will create procedures that receive information about an incident and use helper procedures to determine how the response should be handled.
Prototype:
- A reference guide, runnable Python examples, procedure and parameter practice, Code Runner challenges, and a scaffolded homework task.
- Students revise their procedures after seeing program output or receiving feedback.
- Excellence means correctly using procedures, parameters, arguments, and helper procedures while explaining how decomposition makes the program easier to organize and reuse.
Test:
- Ask peers in peer review to complete the practice activities without additional explanation.
- Observe whether peers can correctly identify parameters and arguments and understand how a procedure calls a helper procedure.
- Compare the lesson with another lesson that is posted.
- Use the findings to revise any instruction or rubric criterion that did not guide students clearly.
- On submission, collect evidence from Code Runner output, practice activities, student explanations, and grading results.
- After teaching, grading, and analysis, return to the lesson and revise it to complete the teaching cycle for continuous improvement.
3. College Board Requirements
APCSP Connection
This lesson supports the AP Computer Science Principles programming concepts involving procedures, parameters, arguments, and procedural abstraction.
Students practice:
- Creating procedures using
def. - Calling procedures to execute reusable instructions.
- Using parameters to allow procedures to work with different data.
- Passing arguments into procedures.
- Using procedures to organize and simplify a larger program.
- Using decomposition by having one procedure call another procedure.
- Creating reusable code instead of repeating the same instructions.
Connection to Lesson
In the Poway Neighborhood Emergency Corps simulation, procedures allow the program to handle different incidents without rewriting the same code.
4. Lesson Plan
Learning Objective: By the end of this lesson, you will be able to define Python procedures with parameters, pass argument values into procedures, and call helper procedures inside larger procedures to organize an emergency-response program.
Success Criteria:
You can:
- Define a Python procedure using
def. - Use parameters to make a procedure reusable.
- Call a procedure with different arguments.
- Explain the difference between a parameter and an argument.
- Call a helper procedure from inside another procedure.
- Use decomposition to break a larger task into smaller procedures.
Tech Talk (3 minutes) Imagine a community emergency-response organization receiving reports about different incidents. The program should not need completely different code for every incident. Instead, we can create procedures that can be reused with different information.
The Rule: Define reusable procedures with parameters, then call them with arguments.
Why do we do this? It reduces repeated code, makes programs easier to organize, allows the same code to work with different data, and make programs easier to modify and debug.
What is calling a procedure?
A procedure, called a function in Python, is a named set of reusable instructions.
- Reusability: You can call a procedure multiple times with different incident locations or types without rewriting the code.
- Definition vs. Calling: Defining creates the procedure (
def); calling executes it with parentheses (). - Execution: Calling allows you to run the same code instructions whenever you need them without retyping them.
Passing Inputs (Parameters)
You can make procedures more flexible by giving them parametersβinput variables that hold data passed into the procedure when you call it.
- Parameters act as temporary placeholders inside the procedure definition.
- Arguments are the actual values passed into the procedure when you call it.
This allows a single procedure to run the same set of instructions on completely different data without rewriting the code.
Quick Knowledge Check: Calling Procedures
-
What is a procedure (function) in Python?
A. A variable that stores a number
B. A named set of reusable code instructions
C. A value passed into a procedure
D. A type of loop
-
What is the difference between defining and calling a procedure?
A. Defining runs the code, while calling creates the procedure
B. Defining creates the procedure, while calling executes it
C. They mean exactly the same thing
D. Calling requires
def, while defining requires parentheses -
In the code below, what is
location?def report_incident(location): print("Incident reported in " + location)A. An argument
B. A parameter
C. A procedure call
D. A return value
-
What is an argument in a procedure?
A. A placeholder used inside the procedure definition
B. The actual value passed into a procedure when it is called
C. The name of the procedure
D. A type of loop
-
Why are parameters useful in procedures?
A. They allow the same procedure to work with different data
B. They make the procedure run only once
C. They remove the need to call the procedure
D. They prevent the procedure from being reused
Calling Procedures Inside Procedures (Decomposition)
In computer science, large problems are broken down into smaller stepsβa process called decomposition.
- An outer procedure handles the main task (like processing an incident report).
- A helper procedure handles a specific sub-task (like checking whether an incident is a priority) and returns a result to the outer procedure.
Each step can become its own procedure, and one procedure can call another one. This allows programs to become easier to read, use, and debug.
5. Code Examples
A. Simple: Defining and Calling a Procedure with Parameters
This example demonstrates how a procedure can receive different information through parameters and arguments.
Code Runner Challenge
Simple code example
View IPYNB Source
# CODE_RUNNER: Simple code example
# Simple Procedure Example
def report_incident(location, incident_type):
print("Incident reported in " + location + ": " + incident_type)
# Calling the procedure with different arguments
report_incident("Poway", "Medical Emergency")
report_incident("Poway", "Power Outage")
B. Complex: Decomposition with Helper Procedures
This example demonstrates how a larger procedure can call a helper procedure to complete part of a task.
Code Runner Challenge
Complex Decomposition Example
View IPYNB Source
# CODE_RUNNER: Complex Decomposition Example
# Complex Decomposition Example
# Helper Procedure
def check_priority(incident_type):
return incident_type == "Medical Emergency"
# Outer Procedure
def process_incident(location, incident_type):
priority = check_priority(incident_type)
if priority:
print("PRIORITY RESPONSE: " + incident_type + " reported in " + location)
else:
print("INCIDENT RECORDED: " + incident_type + " reported in " + location)
# Test calls
process_incident("Poway", "Medical Emergency")
process_incident("Poway", "Power Outage")
6. Popcorn and Homework Hacks
Prepare Submission File
- Open your portfolio repository in VS Code.
- Inside of your
_notebooksfolder, create a new file:YYYY-MM-DD-calling-procedures-hw.ipynb. - Add a markdown cell at the top with the specific frontmatter:
---
layout: post
categories: [Python, Calling-Procedures]
lesson_language: Python
lesson_topic: Calling-Procedures
lesson_part: interactive
lesson_type: lesson
title: 3.12 Calling Procedures HW
permalink: /csp/python/calling-procedures/hw
Authors: Name
---
- Add the necessary code cells for each task, making sure to title each section (use Markdown block).
- Run all cells to check output before committing.
Popcorn Hack 1: Simple Procedure Call & Parameters
Concept: Define a procedure with parameters to perform a single reusable task.
Task:
- Define a procedure called
report_status(location, status). - The procedure should print:
Status update from [location]: [status] - Call the procedure twice using different locations and statuses.
Code Runner Challenge
Procedures Popcorn #1
View IPYNB Source
# CODE_RUNNER: Procedures Popcorn #1
def report_status(location, status):
# TODO: Print a status update using both parameters
pass
# TODO: Call report_status() two times
# TODO: Use a different location or status for each call
Popcorn Hack 2: Decomposition & Helper Procedures
Concept: Break down a complex problem into smaller helper procedures that can be called inside an outer main procedure.
Task:
- Define a helper procedure called
is_priority(incident_type). - It should return
Trueif the incident type is"Medical Emergency". - Define an outer procedure called
process_report(location, incident_type). - Inside
process_report(), callis_priority(). - Print a different message depending on whether the incident is a priority.
- Call
process_report()twice with different incident types.
Code Runner Challenge
Pseudocode Template (COMPLETED EXAMPLE) of Popcorn Hack 2
View IPYNB Source
# CODE_RUNNER: Pseudocode Template (COMPLETED EXAMPLE) of Popcorn Hack 2
PROCEDURE is_priority(incident_type)
{
RETURN (incident_type = "Medical Emergency")
}
PROCEDURE process_report(location, incident_type)
{
priority β is_priority(incident_type)
IF (priority)
{
DISPLAY("PRIORITY: " + incident_type + " reported in " + location)
}
ELSE
{
DISPLAY("STANDARD REPORT: " + incident_type + " reported in " + location)
}
}
process_report("Poway", "Medical Emergency")
process_report("Poway", "Power Outage")
Code Runner Challenge
Popcorn Hack 2 - Decomposition & Helper Procedures
View IPYNB Source
# CODE_RUNNER: Popcorn Hack 2 - Decomposition & Helper Procedures
# Helper Procedure
def is_priority(incident_type):
# TODO: Return True when the incident is a "Medical Emergency"
pass
# Outer Procedure
def process_report(location, incident_type):
# TODO: Call is_priority() using incident_type
# TODO: Store the returned value in a variable
# TODO: Use an if/else statement
# TODO: Print a priority message if priority is True
# TODO: Otherwise, print a standard report message
pass
# TODO: Call process_report() two times
# TODO: Test it with different incident types
Homework Hack (10 minutes)
Task
In the same portfolio notebook, add a new code cell below your interactive tasks and create a simplified emergency-response program.
Your program must contain:
- A helper procedure called
check_priority(incident_type). - An outer procedure called
dispatch_response(location, incident_type). dispatch_response()must callcheck_priority().check_priority()must return a Boolean value.dispatch_response()must print a different response depending on the returned value.- Call
dispatch_response()at least three times with different incident types.
Use at least two different locations or incident types.
# Homework Hack
def check_priority(incident_type):
# TODO: Return True when the incident requires priority handling
pass
def dispatch_response(location, incident_type):
# TODO: Call check_priority()
# TODO: Store the returned value in a variable
# TODO: Use an if/else statement to print the appropriate response
pass
# TODO: Call dispatch_response() at least three times
7. Grading Plan
| Part | Points | What earns the points |
|---|---|---|
| Popcorn Hack 1 | 0.2 | Defines and calls a procedure with parameters using different arguments. |
| Popcorn Hack 2 | 0.2 | Creates a helper procedure and calls it from an outer procedure. |
| Homework: Procedures | 0.2 | Correctly defines both required procedures with parameters. |
| Homework: Parameters & Arguments | 0.15 | Uses arguments correctly when calling the procedures. |
| Homework: Helper Procedure | 0.15 | Calls the helper procedure from inside the outer procedure. |
| Homework: Output | 0.1 | Program runs correctly and produces the expected outputs. |
| Total | 1.0 | Β |
Quick Validation Checklist
- Both Popcorn Hacks run successfully.
- Procedures are created using
def. - Procedures contain appropriate parameters.
- Procedures are called with arguments.
- The outer procedure calls the helper procedure.
- The helper procedure returns a value.
- The program uses decomposition.
- The program does not repeat the same code unnecessarily.
- All code cells run without errors.
8. Lesson Revisions
Revision Made
Reduced explanation text to three bullet points, replaced theoretical game discussions with direct in-browser Code Runner challenges, and structured the Popcorn Hack so it can be completed in around 5 minutes.
9. Feedback Evidence
Peer reviewers noted that the original lesson was dense, taking over 5 minutes to read, and lacked interactive execution elements on the page.
10. References
College Board. (2024). AP Computer Science Principles course and exam description. College Board. https://apcentral.collegeboard.org/media/pdf/ap-computer-science-principles-course-and-exam-description.pdf
Grover, S., & Pea, R. (2013). Computational thinking in Kβ12: A review of the state of the field. Educational Researcher, 42(1), 38β43. https://doi.org/10.3102/0013189X12459518
Submit Assignment
Need to update a submission later? Open the submissions dashboard.