AP CSP - Python with CodeX - Defining Functions

Defining Functions Lesson Plan

Defining Functions

Students learn what abstraction and functions are, then define and call functions in their Mission 3 program.

⏰ 45 min 🎯 Grades 9-12 💻 CodeSpace 🎮 CodeX 🐍 Python
View Lesson Outline
📋

Overview

This lesson introduces functions before they appear in a Mission or CodeTrek. Students first learn what abstraction and functions are. Then they return to the program they created in Mission 3 and define and call functions in it.

🎯 Mission Goal: Students will learn to define and call functions.

🎯

Learning Targets

  • I can define "abstraction" and "function".
  • I can identify places in code where a function can be defined.
  • I can define a function that accomplishes a task.
  • I can call a function in code.
  • I can state benefits for using functions.
💡

Key Concepts

  • A function is a form of procedural abstraction. It hides the details of accomplishing the task.
  • Abstraction is an integral part of computer science and coding.
  • Programmers write functions that accomplish a task.
  • A function can be called multiple times and in any order in a program.
  • A function must be called before its code is executed.
✅

Assessment Opportunities

☑️

Success Criteria

  • Define "abstraction" and "function"
  • Correctly define a function
  • Understand how and when to call a function
  • Define and call one or more functions in a program
  • Determine when a function should be used in code
📁

Digital Resources

🧰

Classroom Materials

  • ▸CodeX (one per student or pair)
  • ▸USB-C cable
  • ▸Computer
🌍

Real-World Applications

The process of hiding complex procedures in a system is widespread.

🛒E-commerce platforms use functions to calculate shipping.
🏦Banking software wraps multi-step validation and security checks in a single procedure.
🗺️Interactive maps give you the option of looking at just one type of information, like traffic or topography.
🔤

Vocabulary

▾
Abstraction - The process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics.
Function - A named set of instructions that accomplishes a task.
🐍

New Python Code

▾
def turn_red(): color = RED pixels.set(0, color)Define a function
# Main program turn_red()Call a function
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-03

CSTA Standards - Grades 11-12

3B-AP-16 3B-AP-22 3B-AP-23

AP CSP Framework - Learning Objectives

AAP-3.A - Write statements to call procedures.
AAP-3.B - Explain how the use of procedural abstraction manages complexity in a program.
AAP-3.C - Develop procedural abstractions to manage complexity in a program by writing procedures.

AP CSP Framework - Computational Thinking Practices

3.B - Use abstraction to manage complexity in a program.
3.C - Explain how abstraction manages complexity.
📝
Preparing for the Lesson
  • Students modify their Mission 3 program, so make sure they can find it in the CodeSpace Sandbox. If a student needs code to start from, have the solution code for Pixels1_final (Mission 3) ready.
  • If you have a word wall, or another form of vocabulary presentation, prepare the new terms (abstraction and function).
  • At the end of the lesson, you will discuss clearing the CodeX before turning it in. Have the Clearing CodeX slides ready.

🧑‍🏫
Teacher Notes
  • Functions are a vital concept for AP CSP, and students should have a lot of practice defining and calling functions. This lesson has students modify the program they created in Mission 3 by defining functions.
  • This lesson is completed on the computer, using the Sandbox in CodeSpace for programming. It is not part of a mission.
  • Students should do a "Save As" with each program to keep the original code.
  • Students will modify a previous program. The best experience will come from them modifying their own code. However, we want all students to be engaged, so you can give them the original code from Mission 3 to modify if needed.
  • Follow the slides for instructions and guidance. Solution code for the final program with functions is provided.
  • You can add the vocabulary to a word wall and keep a document or chart of the Python code learned during each mission.
🗺️

Lesson Outline

This outline gives the narration for one way to present the lesson.

🗣️Warm-up: Functions and Abstraction (10 min)

This short warm-up introduces abstraction and functions. Students take guided notes on their Activity Guide.

Teaching tip: Go through slides #1-8. Include any student discussion about abstraction and functions. Discussion can also wait until the wrap-up, when students have experience with these two new terms.
💻Activity - Modify Mission 3 (20 min)

Students work in pairs (or individually) at their computers.

Teaching tip: You can go over the instructions with the students, or you can use the slides (slides 9-15). Students are asked to modify their code from Mission 3. Students should be able to use their own code. However, if you want to give them code to use, use the solution code for Pixels1_final (Mission 3).
🚀Challenge (optional - 10 min)

Students work in pairs (or individually) at their computers.

Teaching tip: A challenge is not explicitly given in the Activity Guide or slides. However, if you have more time during the class period, have students create more functions for the pixels and call the functions in the main program for a fabulous light show.

✅ You decide what you want students to turn in for a grade, and how they turn it in: the Activity Guide and/or the Pixels1_functions program. You can look at the code on student computers, or have them submit code. The Activity Guide can also be turned in.

🧑‍🤝‍🧑Wrap-Up (5 min)

The wrap-up can be very short for this lesson (slides 27-28). This is the class's chance to review abstraction and functions and make their own meaning with the terms.

Formative assessment:

  • Daily reflection journal
  • Class discussion on what they learned about abstraction and functions
  • Activity Guide completion
  • Defining and calling functions in Mission 3
  • Exit ticket