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("Lakeview")
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()

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 Neighborhood Emergency Corps simulation, procedures allow the program to handle different incidents without rewriting the same code.

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

  1. 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

  2. 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

  3. 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

  4. 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

  5. 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.

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("Lakeview", "Medical Emergency")
report_incident("Lakeview", "Power Outage")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

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("Lakeview", "Medical Emergency")
process_incident("Lakeview", "Power Outage")

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn and Homework Hacks

Popcorn Hack 1: Simple Procedure Call & Parameters

Concept: Define a procedure with parameters to perform a single reusable task.

Task:

  1. Define a procedure called report_status(location, status).
  2. The procedure should print: Status update from [location]: [status]
  3. 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
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

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:

  1. Define a helper procedure called is_priority(incident_type).
  2. It should return True if the incident type is "Medical Emergency".
  3. Define an outer procedure called process_report(location, incident_type).
  4. Inside process_report(), call is_priority().
  5. Print a different message depending on whether the incident is a priority.
  6. 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("Lakeview", "Medical Emergency")
process_report("Lakeview", "Power Outage")

Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

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
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Homework Hack

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:

  1. A helper procedure called check_priority(incident_type).
  2. An outer procedure called dispatch_response(location, incident_type).
  3. dispatch_response() must call check_priority().
  4. check_priority() must return a Boolean value.
  5. dispatch_response() must print a different response depending on the returned value.
  6. 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

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

All Python lessons