AP CSP CodeX - Functions with Parameters Lesson 1

Unit 3 Lesson Plan

Functions with Parameters Lesson 1

Students add parameters to functions in two programs they have already written, and learn how parameters, arguments, and local variables work.

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

Overview

Functions have been used in almost all programs beginning with Mission 3, but they do not require a parameter until Mission 9. This lesson builds on that foundation. Students revisit programs they have already written and add parameters to functions and arguments to function calls. Students work at the computer in CodeSpace, modifying two programs. The lesson also goes over local variables.

🎯 Mission Goal: Students learn about parameters, arguments, and local variables.

🎯

Learning Targets

  • I can identify a parameter and what it is used for.
  • I can identify a local variable and what it is used for.
  • I can determine when to use a parameter and local variable.
  • I can use parameters in functions.
  • I can use arguments in function calls.
💡

Key Concepts

  • A parameter is used in a function when it needs information from the main program to complete a task.
  • Using a parameter with a function is a form of procedural abstraction because the details of how the function accomplishes a task are hidden.
  • Local variables are defined inside a function and can only be used in the function.
✅

Assessment Opportunities

☑️

Success Criteria

  • Identify parameters in a function definition and state what they are used for
  • Identify local variables in a function definition and state what they are used for
  • Use parameters in a function
  • Use arguments in a function call
🧰

Classroom Materials

  • ▸CodeX
  • ▸USB-C cable
  • ▸Computer
🌍

Real-World Applications

💬Messaging apps, where one send-message function works for every contact because the recipient and the text are parameters.
🎮Video games, where a single function can add points for any player, with the player and the amount passed in.
🌡️Thermostats and smart home devices, where one function can set the temperature for any room, with the room and the target as parameters.
🚀

Extensions & Cross-Curricular

ExtensionStudents who finish early add a second parameter to one of the functions (for example, a number that picks which pixel to light) and update every function call with a matching argument.
ExtensionStudents predict what happens if a function call has fewer arguments than the function has parameters, then try it and read the error message.
MathConnect to function notation. In f(x) = 2x + 3, x is the parameter, and in f(5) the value 5 is the argument. Students evaluate f for several arguments.
ScienceA science formula such as speed = distance / time works like a function with two parameters. Students describe which values would be the arguments for a 100 meter race run in 20 seconds.
Lang ArtsStudents write a short explanation of parameter versus argument using an everyday comparison, such as a Mad Libs sentence where the blanks are the parameters and the words students fill in are the arguments.
🔤

Vocabulary

▾
Function (review) - A named set of instructions that accomplishes a task. (A named chunk of code you can run anytime just by calling its name; also called a procedure.)
Procedural abstraction - The technique that breaks down complex tasks into smaller, more manageable procedures.
Global variable - A variable defined outside a function that retains its value throughout program execution and can be used anywhere in the code.
🐍

New Python Code

▾
def turn_pixel(color):
def game(message, button):
Function definition with parameter.
turn_pixel(RED)
game("Press B", BTN_B)
Function call with argument.
📐

Standards

▾

CSTA Standards - Grades 9-10

3A-CS-03 3A-AP-13 3A-AP-16 3A-AP-17 3A-AP-18 3A-AP-21

CSTA Standards - Grades 11-12

3B-AP-10 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-17 3B-AP-23

AP CSP Framework

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.
Computational Thinking Practice 3.A - Generalize data sources through variables.
Computational Thinking Practice 3.B - Use abstraction to manage complexity in a program.
📝
Preparing for the Lesson
  • Students modify their own programs from earlier lessons: Pixels1_RGB (RGB Colors Lesson, Unit 1) and Billboard_functions (Mission 7 Obj 7-9, Unit 2). Make sure students can find both programs in CodeSpace.
  • If a student does not have a program, the most recent final version of each one is in the class dashboard, so all students can start in the same place.
  • Review the slides, which give the instructions and guidance for the lesson.

🧑‍🏫
Teacher Notes
  • This lesson is completed on the computer, using the Sandbox in CodeSpace for programming. It is not part of a mission.
  • Students add parameters to functions in the Pixels1_RGB and Billboard_functions programs.
  • The best experience comes from students modifying their own code. However, we want all students to be engaged, so you can give them the original code to modify if needed.
  • Solution code for both finished programs is in the class dashboard.
  • Follow the slides for instructions and guidance.
🗺️

Lesson Outline

Follow the slides for instructions and guidance. Students work at computers in the CodeSpace Sandbox.

🗣️Warm-up

Review functions with students.

Teaching tip - slide #2: Students write three or more things they know about functions in their activity guide. You can have them do a think-pair-share, etc.
Teaching tip - slides #3-4: Review the definitions.
💻Example #1 - Pixels1_RGB

💻 Students will work at computers for this lesson. They will use the Pixels1_RGB program from the Unit 1 RGB Colors lesson.

Teaching tip - slides #5-8: Go through these slides as preparatory information. Students refer to their program Pixels1_RGB from Unit 1. If they do not have the file, you can give it to them so all students start in the same place.
Teaching tip - slides #9-24: These slides give step-by-step instructions for defining a function with parameters for the program. The slides also introduce "parameter" and "argument."
💻Example #2 - Billboard_functions

Students will use the Billboard_functions program from Unit 2 Mission 7.

Teaching tip - slides #25-27: Students add a parameter to a function, and a comparison is made between a parameter and a local variable.
Teaching tip - slides #28-30: These slides go over local variables and parameters. They prepare students for the final questions on the activity guide.

✅ The activity guide and two programs are complete and ready to turn in.

🧑‍🤝‍🧑Wrap-Up

Formative assessment:

  • Check for Understanding at the end of the Activity Guide
  • Daily reflection journal or Google Form
  • Class discussion on what they learned about functions with parameters
  • Exit ticket