Podcast
Writing Functions with Parameters on Paper
Students are working together in small groups to create "paper code" for a function that calculates the area of different polygons based on the number of sides and side length. The teacher introduces the concept of writing reusable functions and explains how parameters help make functions more flexible. One group writes a procedure that calculates the area of a triangle and tests it by using different side lengths. Another group focuses on squares and hexagons, adjusting their parameters to handle various shapes.
As they complete their "paper code," students realize that by changing just the input values, they can use the same procedure for any regular polygon.
Objective:
Students will practice writing functions on paper that calculate the area of polygons based on the number of sides and the side length. By using parameters, they will explore how these procedures can be reused for different inputs, making their "code" more flexible and efficient.
Materials Needed:
Graph paper
Pencils
Examples of area formulas for regular polygons
Steps:
Introduction:
Start by discussing how functions with parameters make it easier to reuse code in programming.
Ask students to think about how they would write a general function to calculate the area of any polygon, regardless of how many sides it has.
Introduce the concept of parameters, such as the number of sides and the length of each side, and explain how these values can be passed into a function.
Group Activity:
In small groups, students will write their own "paper code" for a function called calculateArea(numSides, sideLength) that calculates the area of a regular polygon.
They will first write the general structure of the function and then insert the formula for calculating the area based on the parameters.
Each group will try different values for numSides and sideLength to test their function on paper.
Testing and Refining:
Students will exchange their written functions with another group and use different inputs to test the accuracy of the code.
If the area calculations don't match the expected result, they will refine their function by correcting errors in the formula or parameter handling.
Presentation and Discussion:
Each group will present their function and explain how they used parameters to make it work for any polygon.
Lead a class discussion on the importance of creating reusable functions and how using parameters allows for flexibility in solving a wide range of problems.
Equity and Access:
Provide a list of basic area formulas and examples of how to structure functions for students who need extra support. Allow students to work in pairs to encourage peer assistance, and offer additional guidance on creating general procedures.
Real-World Application:
Connect this activity to real-world programming, where engineers and developers use functions with parameters to handle repetitive tasks more efficiently. For example, functions that calculate areas or process data are widely used in industries like architecture, construction, and game development.
CS Practice(s):
Creating Computational Artifacts: Students create a procedure to calculate polygon areas, demonstrating the flexibility of using parameters.
Recognizing and Defining Computational Problems: Students break down the task of calculating areas for various polygons into manageable subproblems by creating a generalized function.
Standard(s):
CA CCSS Mathematics 6.G.1
CA CS 6-8.AP.14
Calculating Polygon Areas with Code
Students are using Pencil Code to create a function that calculates the area of polygons. The teacher begins by introducing how functions with parameters can make code more flexible and reusable. One group writes a function to calculate the area of a triangle by passing the base and height as parameters, while another group creates a function to calculate the area of squares and hexagons.
As the students test their code, they see how changing the parameters can easily generate different outputs for different polygons. Students are excited to watch the code in action, making math come alive through coding.
Objective:
Students will use Pencil Code, p5.js, App Lab, or another coding platform to write a function that calculates the area of different polygons based on the number of sides and side length. They will explore how using parameters allows them to reuse their function for various inputs, making their code flexible and efficient.
Materials Needed:
Computers with internet access and Pencil Code (https://pencilcode.net/) or another coding platform
Projector and/or whiteboard for group discussions
Steps:
Introduction:
Students explore the concept of writing reusable functions in coding and learn how parameters can be used to pass in different values.
Discuss how this approach saves time and effort, allowing programmers to use one function for many different problems.
Demonstrate an example of how a function with parameters works in Pencil Code and other coding platforms, such as function calculateArea(numSides, sideLength).
Group Activity:
In pairs or small groups, students will open a coding platform and write their own function to calculate the area of a regular polygon.
The function will take two parameters: numSides (the number of sides) and sideLength (the length of each side).
Guide students through writing the basic structure of the function and implementing the formula for calculating the area of regular polygons.
They will test their function by calling it with different values for numSides and sideLength to calculate areas for triangles, squares, pentagons, and more.
Creating and Coding:
After writing the basic function, encourage students to modify their code by adding more features, such as drawing the polygon on the screen.
They can use the built-in drawing functions in a coding platform to visually represent the polygons and label them with their calculated areas.
Testing and Refining:
Students will run their code and observe the results, checking if the areas are calculated correctly.
They will experiment by passing different values into their function, refining the code if the output is incorrect.
Students will also use loops to repeat drawing different polygons with varying parameters.
Presentation and Discussion:
Each group will present their completed functions, demonstrating how their code calculates the area of different polygons by passing in parameters.
Discuss as a class how using parameters makes the code more efficient and easier to reuse in different scenarios.
Encourage students to reflect on how this approach is used in real-world applications.
Equity and Access:
Provide sample code templates for students who need extra support to get started. Pair students with varying levels of coding experience to promote collaboration, and ensure that all students can participate by offering differentiated tasks, such as visualizing polygons or focusing on the calculations.
Real-World Application:
Connect the lesson to real-world coding practices, such as how engineers and architects use functions to calculate measurements for building designs. Explain how creating reusable code helps programmers solve a wide range of problems more efficiently in areas like game development, robotics, and simulations.
CS Practice(s):
Creating Computational Artifacts: Students will design functions with parameters to calculate the area of polygons, enabling flexibility in their code.
Testing and Refining Computational Artifacts: Students will test their functions with different inputs, refining the code based on the results to ensure accurate area calculations.
Standard(s):
CA CCSS Mathematics 6.G.1
CA CS 6-8.AP.14
Click the button above to unlock our Lesson Idea Design Tools! Our custom chatbots are ready to help you navigate content standards, integrate both UDL Concepts and UN Sustainable Goals, and design lesson ideas that align with content standards and incorporate computer science concepts.
If you are using a free ChatGPT account, there will be daily limits on usage. This AI tool is meant to be a guide. You are the professional. Be sure to vet all responses.