Learning Resource Type

Classroom Resource

Computer Science Principles Unit 3 Chapter 1 Lesson 8: Creating Functions With Parameters

Subject Area

Digital Literacy and Computer Science

Grade(s)

9, 10, 11, 12

Overview

In this lesson, students practice using and creating functions with parameters. Students learn that writing functions with parameters can generalize solutions to problems even further. Especially in situations where you feel like you are about to duplicate some code with only a few changes to some numbers, that is a good time to write a function that accepts parameters. In the second half of the lesson, students make a series of modifications to a program that creates an “Under the Sea” scene by adding parameters to functions to more easily add variation to the scene. Lastly, students are introduced to App Lab’s random number functions to supply random values to function calls so the scene looks a little different every time the program runs.

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.

Note: You will need to create a free account on code.org before you can view this resource.

    Digital Literacy and Computer Science (2018) Grade(s): 09-12

    DLCS18.HS.3

    Differentiate between a generalized expression of an algorithm in pseudocode and its concrete implementation in a programming language.

    Unpacked Content

    UP:DLCS18.HS.3

    Vocabulary

    • pseudocode
    • programming language
    a.
    • approximated
    b.
    • iteration
    • conditional statements
    • control structures
    c.
    • iterative loop
    • selection constructs
    • recursion

    Knowledge

    Students know:
    • that differences exist in pseudocode and a programming language.
    • that programming languages have certain requirements for language and syntax.
    a.
    • that some programs cannot return a result in a reasonable time frame, therefore approximations must be allowed in those cases.
    b.
    • how to identify sequential statements, conditional statements, and/or iterations in code.
    • the differences between sequential statements, conditional statements, and/or iterations.
    • trade-offs exist with using one control structure over another.
    c.
    • some decisions in a program will require the use of iterative loops, selection constructs, or recursion.
    d.
    • programs can be written to satisfy a number of needs such as performance, reusability, and ease of implementation.
    • that most times, algorithms will differ based on the need of the program; performance, reusability, or ease of implementation.
    e.
    • that programs can be written with specific priorities in mind.
    • that there are multiple correct ways to write a program.
    • that solutions are often chosen to meet the priority need of the program.

    Skills

    Students are able to:
    • distinguish between a generalized expression of an algorithm in pseudocode and its concrete implementation in a programming language.
    • point out similarities in vocabulary and syntax between pseudocode and an algorithm.
    • point out differences in vocabulary and syntax between pseudocode and an algorithm.
    a.
    • explain that some algorithms do not lead to exact solutions in a reasonable amount of time and thus approximations are acceptable.
    b.
    • identify sequential statements, conditional statements, and/or iterations in code.
    • identify tradeoffs associated with using one control structure over another.
    c.
    • distinguish when a problem solution requires decisions to be made among alternatives or when a solution needs to be iteratively processed to arrive at a result.
    d.
    • evaluate and select algorithms based on performance, reusability, and ease of implementation.
    e.
    • explain how more than one algorithm may solve the same problem and yet be characterized with different priorities.

    Understanding

    Students understand that:
    • similarities and differences exist in pseudocode and programming code.
    • some programming languages more closely resemble pseudocode than do other programming languages.
    a.
    • due to time or financial constraints, some programs may return an approximation of a solution.
    b.
    • both benefits and drawbacks exist when selecting one control structure over another in a code.
    c.
    • programs can use multiple methods to arrive at a solution.
    d.
    • there are times when a program needs to be selected for a specific purpose, such as performance, reusability, and/or ease of implementation.
    e.
    • multiple algorithms can solve the same problem.
    • algorithms can operate with a specific priority in mind, such as speed, simplicity, and/or safety.
    Digital Literacy and Computer Science (2018) Grade(s): 09-12

    DLCS18.HS.6

    Decompose problems into smaller components through systematic analysis, using constructs such as procedures, modules, and/or objects, with parameters, and which return a result.

    Unpacked Content

    UP:DLCS18.HS.6

    Vocabulary

    • parameters
    • procedures
    • modules
    • objects
    • control structures

    Knowledge

    Students know:
    • removing unessential details can make a process simpler.
    • control structures can assist in programming decisions.
    • how to create a program that returns a result.

    Skills

    Students are able to:
    • decompose a problem.
    • create a program that returns a result.
    • implement control structures.

    Understanding

    Students understand that:
    • removing unessential details can make a process simpler.
    • control structures can assist in programming decisions.
    Digital Literacy and Computer Science (2018) Grade(s): 09-12

    DLCS18.HS.8

    Demonstrate code reuse by creating programming solutions using libraries and Application Programming Interfaces.

    Unpacked Content

    UP:DLCS18.HS.8

    Vocabulary

    • code
    • programming languages
    • Application Programming Interfaces

    Knowledge

    Students know:
    • how to design a programming application that reuses code from programming libraries and code created in previous applications.

    Skills

    Students are able to:
    • reuse code from previous applications, code libraries, or APIs to reduce coding workload.

    Understanding

    Students understand that:
    • reuse of code can be time
    • saving.
    • code may be written and shared in code libraries or may be accessible as an API.
    Link to Resource

    CR Resource Type

    Lesson/Unit Plan

    Resource Provider

    Code.org
    Accessibility
    License

    License Type

    CUSTOM
    ALSDE LOGO