AP CSP CodeX - Functions with Parameters Lesson 2

Functions with Parameters Lesson 2 Lesson Plan

Functions with Parameters Lesson 2

Students add parameters to functions in three programs, then review when to use parameters and local variables.

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

Overview

Students work on computers in the CodeSpace Sandbox. This lesson is not part of a mission. Students add parameters to functions in three programs they have already written: Answer_Bot (Unit 2 Mission 8), Heart2_functions (Unit 2 Mission 6), and Display_functions (Unit 1 Mission 4). They then review when to use a parameter and when to use a local variable, and complete the questions on the Activity Guide.

🎯 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.
  • A parameter can be any data type, including a bitmap image, a string, a button, Boolean, etc.
✅

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
🚀

Extensions & Cross-Curricular

ExtensionStudents add a second parameter to turn_pixel() so the function also sets which pixel to light, then call it with different pixel numbers and colors.
ExtensionStudents call game() with a new message and a different button, such as game("Press A", BTN_A), and build their own button-press game from several calls.
MathStudents predict how the delay in Answer_Bot_parameters changes if the random number is divided by 100 instead of 10, then test their prediction.
Lang ArtsStudents write a short explanation of the difference between a parameter and an argument, using an everyday example, for a classmate who missed the lesson.
🔤

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
  • Make sure students can open their Answer_Bot_functions, Heart2_functions, and Display_functions programs in the CodeSpace Sandbox. Students who need the original code can use the most recent final version of each program from the class dashboard.
  • Prepare the Activity Guide to give to students. It is used for notes during the lesson and for the review at the end.
  • If you have a word wall, or another form of vocabulary presentation, prepare the terms.

🧑‍🏫
Teacher Notes
  • Students complete this lesson on the computer, using the Sandbox in CodeSpace for programming. This lesson is not part of a mission.
  • Students add parameters to functions in three programs. The best experience will come 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.
  • The most recent final version of each program can be found in the class dashboard. The programs come from these missions:
  • Answer_Bot: Mission 8 (Unit 2)
  • Heart2_functions: Mission 6 (Unit 2)
  • Display_functions: Mission 4 (Unit 1)
  • Solution code for all finished programs is provided.
  • Follow the slides for instructions and guidance.
🗺️

Lesson Outline

This outline gives one way to present the lesson.

🗣️Warm-up

Review functions with students.

  • Slide 2: Students write three or more things they know about parameters and arguments in their Activity Guide. You can have them do a think-pair-share, etc.
  • Slides 3-4: Review when to use parameters and procedural abstraction.
💻Example #3 - Answer_Bot

💻 Students work at computers for this lesson. They use the Answer_Bot_functions program from Unit 2 Mission 8.

Teaching tip: Go through slides 5-6. They give instructions for modifying the function and then adding a parameter.
💻Example #4 - Heart2_functions

💻 Students use the Heart2_functions program from Unit 2 Mission 6.

Teaching tip: Go through slides 7-8. They talk about parameters and the variable types that can be used.
Teaching tip: Go through slides 9-13. They give step-by-step instructions for modifying the program with a function and parameters.
💻Example #5 - Display_functions

💻 Students use the Display_functions program from Unit 1 Mission 4.

Teaching tip: Go through slides 14-16. They explain the changes that will be made.
Teaching tip: Go through slides 17-19. They give step-by-step instructions for modifying the function and adding parameters.
📝Review

💻 Students do not use the computer for this activity.

Teaching tip: Go through slides 20-23. Review when to use parameters and when to use local variables. Complete the questions on the Activity Guide.
Teaching tip: Students complete the "Check for Understanding" on the Activity Guide as an individual review. Alternately, they can work on the questions with a partner.

✅ 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 parameters
  • Exit ticket