(Py CS1)_ Lesson 2 - Arguments & Properties
(Py CS1)_ Lesson 2 - Arguments & Properties
Quest #2
Arguments & Properties
Let’s Review…
CODING CONCEPTS
1 What did we talk about last time?
COMPLETE QUESTS
4 Are there any quests you want to review?
Quest #2
By the end of my quest, I
will be able to…
💎 Pass arguments to a
method call.
💎 Predict the output of a
program that contains
calls to methods.
💎 Debug a program
that contains calls to
methods.
Arguments
ogre.defend()
hero.moveUp(2
)
Method Arguments
An argument contains information that describes how
an action will be performed. We pass arguments to
method calls.
These heroes have gathered to do homework but
they aren’t sure what homework to do or for how
What
homework
long.
should I do? What values could you give our heroes that would How long
help them do their homework? should I
Imagine you’re calling the method named work?
doHomework, like so:
hero.doHomework(? )
Python
Types of Values
Computers differentiate between information that
represents a quantity and information that represents
text.
NUMBERS TEXT
Which of your examples could be Which of your examples could be
expressed as a number? expressed as a word or a string of text?
hero.doHomework(? ) hero.doHomework(? )
hero.doHomework(? ) hero.doHomework(? )
Python
Numeric Data Types
There are two different types of numbers that you will want to
use in your Python programs.
-4 2.3
We should use
both integers and
floats in our -2 100 36.33 -1.8
Python programs!
2663 -0.5574
Integers Floats
(Whole Numbers) (Decimals)
Python
Integers as Arguments Object: abacus
Method:
The method countRed countRed
defines the counting Argument Type:
action to be performed integer
with the abacus. The
method’s argument
describes how many
beads to count as part of abacus.countRed(3)
the action. abacus.countOrange( ? )
abacus.countYellow( ? )
abacus.countGreen( ? )
The statement abacus.countBlue( ? )
abacus.countRed(3) will
count 3 red beads and
move them to the right.
Python
Text Data Type
A string is a sequence of characters, often used to
represent text (e.g. words, sentences, etc.).
G
S
“CodeCombat is “Language” → “age”
awesome!”
Strings as Arguments
The method cook defines the action of cooking a meal. The
method’s argument describes the meal prepared, like
“Spaghetti” or “Pizza”.
Python
Properties
Characteristics that all objects of a single type share.
For example, all hero objects have a name property. The values
for each object’s name may differ.
To the Dungeon!
Let’s put
these
concepts into
action!
Game Recap: Enemy Mine
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
● Comments error messages in
CS1!
● hero.say() or print()
● Inputs and outputs
● Tracing tools
● Debuggers
● Unit tests
Activity: Debugging
The program is intended to make the
hero collect the gem & exit the dungeon
alive. However, it does not work as
intended.
1
1. Where is the error?
2
2. How would you fix this mistake?
Python
Independent Practice
Log into CodeCombat
https://codecombat.com/
Play Levels
CS1 Levels 4 - 8, CC Long Steps, CC Dangerous
Steps, CC Sleepy Hour
Need Help?
Ask a friend or AI!
Key Terms
● Argument: Part of a method call that specifies
how an action is performed.
argumen argumen
t t
hero.moveUp(3 hero.say(“Hi!”)
)
● Pass to: The act of giving a method the
information needed to specify how an action is
performed.
● Property: Characteristics that all objects of a
single type share.
● Type: A set of values that all share the same
characteristics. Python types include strings,
floats, and integers.
Any
5
Questions?
4
6
1
Wrap-Up 1
Describe a scenario
when you might
consider passing
arguments to a
method call. Your
response should
include an example
line of code to be
Wrap Up 2
The hero needs to collect
all of the gems. However,
the algorithm does not
work as intended:
hero.moveRight()
hero.moveDown()
hero.moveUp()
What is wrong? What
would you do to fix this
problem?
Python
Wrap Up 3
Consider the following
algorithm:
hero.moveDown(2)
hero.moveRight()
hero.moveUp()
hero.moveRight()
Describe what would happen
if you were to run this
program. It may help to
examine the dungeon to the
right. Python
Wrap Up
Add your own
formative
question.