0% found this document useful (0 votes)
7 views26 pages

CS2 - Slide Deck 6 - Functions With Parameters

The document discusses the integration of algorithms and abstraction in programming, emphasizing their importance in creating effective programs. It outlines key computational thinking practices such as solution design, code analysis, and the use of functions with parameters to manage program complexity. Additionally, it highlights debugging techniques and procedural abstraction as essential skills for programmers.

Uploaded by

SOE LIN HTET
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views26 pages

CS2 - Slide Deck 6 - Functions With Parameters

The document discusses the integration of algorithms and abstraction in programming, emphasizing their importance in creating effective programs. It outlines key computational thinking practices such as solution design, code analysis, and the use of functions with parameters to manage program complexity. Additionally, it highlights debugging techniques and procedural abstraction as essential skills for programmers.

Uploaded by

SOE LIN HTET
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Today’s Big Ideas

Algorithms and Programming (AAP):


Programmers integrate algorithms and abstraction to create programs for
creative purposes and to solve problems. Using multiple program statements in a
specified order, making decisions, and repeating the same process multiple times
are the building blocks of programs. Incorporating elements of abstraction, by
breaking problems down into interacting pieces, each with their own purpose,
makes writing complex programs easier. Programmers need to think
algorithmically and use abstraction to define and interpret processes that are used
in a program.
Today’s Computational Thinking
Practices
Computational Solution Design:
● 1.A: Investigate a situation, context, or task.
● 1.B: Determine and design an appropriate method or approach to achieve the purpose.
● 1.C: Explain how collaboration affects the development of a solution.
● 1.D Evaluate solution options.

Algorithms and Program Development:


● 2.A: Represent algorithmic processes without using a programming language.
● 2.B: Implement and apply an algorithm.
Today’s Computational Thinking
Practices Continued
Abstraction in Program Development:
● 3.A: Generalize data sources through variables.

Code Analysis:
● 4.A: Explain how a code segment or program functions.
● 4.B: Determine the result of code segments.
● 4.C Identify and correct errors in algorithms and programs including error discovery
through testing.
CodeCombat
Computer Science - 2

Quest #6
Functions with Parameters
Let’s Review…

CODING CONCEPTS
1 What did we talk about last time?

GUIDED PLAY AND INDEPENDENT PRACTICE


2 What activities are you still working on?

CHECK-IN & CONCEPT REVIEW


3 Are you having trouble with a concept?

COMPLETE QUESTS
4 Are there any quests you want to review?
Quest #6
By the end of my quest, I
will be able to…
💎 Define and call a function
with parameters.
💎 Describe how functions
help manage the
complexity of my
programs.

💎 Debug a function definition.


Songs

The song
repeats a
lot!

It’s All Star


by Smash
Mouth!

7
Functions with Parameters
Parameters represent This function
makes the hero
information that we can sing part of a
verse!
pass to a function
definition that modifies its
behavior.

Python
Passing Arguments
You can change
the value you pass
to a function.

Separate each
argument passed The verse
with a comma. function is
called 2 times!

Python
Arguments vs. Parameters
An argument is the
A parameter is a
value that is passed
variable you define
to the function
in your function.
when it's called.
Procedural Abstraction
Procedural abstraction allows
us to generalize our programs so
that they work with a variety of
inputs.
Pros:
● Reduces lines of code
● Easier to read and comprehend
Image Source

● Easier to fix and extend.


Warm-Up Part 1:
In the following code, identify:

1.1 What is the name


of the function?

1.2 What are the


arguments?

2.3 What are the


parameters?

Python
Warm-Up Part 1: Solution
1.
1 sayHello

1.
2 “Amara”,
“15”,“Miss
Hushbaum”,
“32”

2.
3 name, age

Python
Warm-Up Part 2:
Write the program your
hero would need in order I smell at least
to sing this version of Old 2 function
definitions!
MacDonald.

Remember to prioritize
procedural abstraction.
Fewest lines of code wins!
Warm-Up Part 2: Solution
Answers may vary.
Can you beat
21 lines of
code?
To the Forest!

Let’s put these


concepts into
action!
Game Recap: Backwoods Fork

Starter Code 👀
Python
Reminder: Debugging!
You’re going to make mistakes. That’s a very NORMAL part of coding, even for
experts. Finding and fixing errors (debugging) is an important part of
programming. Consider using the following tools when debugging your
programs:
We are going to
● Error messages practice reading error
messages, using
● Comments comments, and
● hero.say() or print() hero.say in CS2!
● Inputs and outputs
● Tracing tools
● Debuggers
● Unit tests
Activity: Debugging
The following program is
intended to safely get inside the
door. However, it does not work.
1.
1 Where is the error?
2.
2 How would you fix this
mistake?

Python
Independent Practice
Log into CodeCombat
https://codecombat.com/play/forest

Play Levels
CS2 Levels 27-36, Concept Challenges: Timberland
Trap, Last Cannon, and Functional Patrol

Need Help?
Ask a friend or AI!
Key Terms
● Parameter: Special variables that are used to
represent the variety of information that can be
given to a function.

Python Syntax:
def name(parameters):
code that uses parameters
● Argument: Specific values that are passed to a
function call.
Python Syntax:
name(arguments)

● Procedural Abstraction: The process of breaking a


problem into only its essential parts. It helps reduce
the complexity of programs.
6
Any Questions? Quest #6
Functions with
Quest #5 Parameters
5
Functions

Quest #4 7 Quest #7
4
Nested Conditionals Events

3 Quest #3
Conditional Statements (Else)
8
2 Quest #2
Conditional Statements (If) CS2
Capstone +
1
Quest #1 Concept
Coordinate Systems Review
Wrap-Up 1
How do functions with
parameters help us
manage the complexity
of our programs?
Hint: Think about the
pros of procedural
abstraction.
Wrap-Up 2
The following program is supposed to make your hero sing Happy
Birthday to Okar. However, the program does not work as intended.

What is wrong? What would you do to fix this problem?


Wrap-Up 3
Consider the following algorithms:
Algorithm A: Algorithm B:

Do these programs produce the same output when executed? If


yes, what is the output of both. If no, explain how they differ.
Wrap-Up
Add your own
formative question.

You might also like