0% found this document useful (0 votes)
3 views

(Py CS1)_ Lesson 2 - Arguments & Properties

This document outlines Quest #2 of a computer science course focusing on method arguments and properties in programming. It covers concepts such as passing arguments, debugging, and the difference between numeric and text data types. The document also includes activities for practice and key terms related to the lesson.

Uploaded by

Joan Fuentes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

(Py CS1)_ Lesson 2 - Arguments & Properties

This document outlines Quest #2 of a computer science course focusing on method arguments and properties in programming. It covers concepts such as passing arguments, debugging, and the difference between numeric and text data types. The document also includes activities for practice and key terms related to the lesson.

Uploaded by

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

CodeCombat

Introduction to Computer Science

Quest #2
Arguments & Properties
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 #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.).

The sequence of characters you write must be contained


within quotation marks if you are creating a string.

A substring is a smaller part of a string.


Examples of strings: R I
““
Examples of substrings:
“Charm” → “arm”
T N
“hello world” “clever” → “lever”

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”.

Remember, a string must always be enclosed in quotation


marks.

Which of the following code statements will successfully help


Omarn make a delicious snack for his friends?
Object: chef
a) chef.cook.Gyro
Method: cook b) chef.cook(“tacos”)
c) chef.cook(Popcorn
Argument ) “Popcorn” “Gyro” “Taco”
Type: string
d) chef.cook(“Gryo”)
Python
Multiple Arguments
Sometimes, a method will need multiple arguments
in order to work.
Separate each argument with a comma.
Which of the following code statements will
successfully help Omarn make tacos his friends?
“cheese”
“lettuce”
Object: chef
a) chef.cook.makeTacos() “meat”

Method: cook b) chef.makeTacos(lettuce, cheese)


c) chef.makeTacos(“lettuce”, “cheese”, “meat”)
Argument d) chef.makeTacos(“lettuce” “cheese” “meat”)
Types: strings

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.

You might also like