Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Functions with Parameters

Similar presentations


Presentation on theme: "Creating Functions with Parameters"— Presentation transcript:

1 Creating Functions with Parameters
Lesson 3-8 AP Computer Science Principles

2 Objectives Students will be able to:
Write functions with parameters to generalize a solution instead of duplicating code. Identify appropriate situations for creating a function with parameters. Use random numbers as inputs to function calls for the purpose of testing. Add parameters to a function in an existing piece of code to generalize its behavior.

3 Parameters In the previous lesson, we learned to use a lot of new turtle commands. Some of these commands accept a parameter, or even many parameters, which allow us to pass values to the function. This allowed us to make much more interesting images by specifying precisely how far the turtle should move or turn, and introduced the ability to choose specific pen sizes and colors.

4 Parameters Parameters are a powerful programming construct. Suppose we have a whole group of similar problems, like turning the turtle some amount. Without a parameter we would need 360 different functions, one for each number of degrees we wanted to turn! Parameters allow us to use a single function that creates a general solution to this group of problems. This is clearly a useful construct to use in our programs, and in today’s lesson we’re going to learn how to create functions with parameters for ourselves.

5 Video

6 Activity Complete Stage 8 through step 12

7 Journal Develop a rule for deciding when to create a function with a parameter rather than a normal function. Below your rule write a couple sentences justifying your rule.

8 Stage 8 Complete Stage 8


Download ppt "Creating Functions with Parameters"

Similar presentations


Ads by Google