Search Header Logo
Children

Children

Assessment

Presentation

Computers

9th Grade

Practice Problem

Hard

Created by

Dawn Madden

Used 2+ times

FREE Resource

19 Slides • 9 Questions

1

media

CMU Unit 3.2.3:

Looping

through Group

Children

AKA Iteration

START!

2

media

What are children in a group?

media
media

3

Multiple Select

Question image

What names can I replace dot with and still make this code run?

1

i

2

number

3

#

4

Number

4

Multiple Select

Question image

What is dot referring to in the line:

for dot in dots.children?

1

referencing each circle in the group dots (in this case 5 circles)

2

only one of the Circles in the group dots

3

it is a variable

4

nothing- it stands for nothing

5

Open Ended

Question image

If I change the variable dot, what must I also change in the code?

6

media

What is iteration?

Iteration is a repetitive portion of an algorithm.
That is, it is a portion of the procedure which
runs until a certain condition is met or a certain
number of times..
We may see this in “for” or “while” loops, or in
code statements like “repeat 3 times” or “if
CAN_MOVE_RIGHT ==TRUE”

7

media

Why do we care about iteration?

In the AP Create task, iteration is required:
You must
Use a loop

The loop must contain an if statement

The loop must be contained in a student-
created function

Hopefully, the loop will make running your
program easier (more about this later)

8

media

At the boards… Draw and execute.

media
media

9

Multiple Choice

Question image

What will happen as a result of this code?

1
2
3
4

10

media

Looping through a group

CREDITS

Start with a group

Let’s use this group

numbers = Group(

Label(1, 50, 50),
Label(2, 70,50),
Label(3, 90, 50),
Label(4, 110,50) )

Let’s change it

for numberValue in numbers.children:

numberValue.fill = 'green'

numberValue.value +=1

What will happen?

11

Multiple Choice

Question image

What would happen here?

1
2
3
4

nothing

12

Multiple Choice

Question image

What would happen here?

1
2
3
4

syntax error

13

media

More examples! Notice the FUNCTION!

14

Multiple Choice

Question image

What do you expect to happen in this code?

1
2
3
4

15

media

CMU Unit 3.3.1:

Lists

Like groups, but better

START!

16

media

What is a list?

A list is a way of storing multiple values in a
single variable. It may also be called an array.

numList = [ ‘one’, ‘two’, ‘three’, ‘four’, ‘five’]

The list is named numList
The elements of the list are ‘one’, ‘two’, ‘three’,
‘four’, ‘five’

17

media

What is an index?

When we talk about where an element is
located on a list, we talk about its index.

numList = [ ‘one’, ‘two’, ‘three’, ‘four’, ‘five’]
Index 0 1 2 3 4

So, numList[2] has the value ‘three’
In Python, the index starts at 0
On the AP Exam, the index starts at 1 (WHY????)

18

Multiple Choice

colorList = ['white', 'red', 'blue', 'green', 'purple', 'orange']

What is the value off colorList[3]?

1

red

2

blue

3

green

4

purple

19

Multiple Choice

colorList = ['white', 'purple', 'orange', 'red', 'blue', 'green', ]

What is the value of colorList [2]

1

whtie

2

purple

3

orange

4

red

20

media

NOTE:

In some programming languages, a list is called
an array.

We will always use the term list,

but if you ever see the word "array", it's just
a list!

21

media

Now you try!

Go to the sandbox

Create a small group

Write a function (student created) that will do
something with the group by looping through it

Call the function using a Mouse Event

Group

Function

MouseEvent

22

media

Lists on the Performance Task

The last 2 points for the CPT involves lists (or Groups) To get
these points, your project must:

Include a list (or Group).

The data stored in the list must be used.

The list must be important for the program. This means
that writing the program without the list would have been
much more difficult or impossible.

You can use a Group! Copy the language you need to use into
your notes!

23

media

Some things we can do with lists

CREDITS

Indexing

We can get data from a list to use in a
variable, like
labelValue = numList[2]
Label (labelValue, 50, 250)

This allows for additional abstraction.
Check it out in the practice problems!

Change values

We can update list values using the
index
numList[2] = ‘twelve’
Changes the value from ‘three’ to
“twelve’

This means it is much easier to
update values in a program!

24

media

More things we can do (the important stuff)

CREDITS

Traversing

Traversing allows us to cycle
through values of a list.

We can use a helper variable
for the index, and just keep
adding one.

Be careful, you don’t want to
fall off the end of the list!

The mod operator %

The “mod” of a number is the
remainder when divided by another
number. Examples

5%2 = 1
17%5 = 2

This can help us avoid errors with
lists

25

media

Traversing a list with mod

26

media

A little challenge using mod

In the section “Looping Through Lists”, the function
“drawColoredCircles” loops through the list of colors.

None of the circles have borders, but I want to give the circles
pink and black borders in an alternating pattern. Can you revise
the code to draw black borders on three circles and pink
borders on the other three?

HINT: Use variables to store the index location
HINT: Use mod to change back and forth between pink and black
HINT: Don’t forget to set a border color to start with!

27

media

In your notes – using mod

Differences?

Similarities?

28

media

Slidesgo

Flaticon

Freepik

CREDITS: This presentation template was created
by Slidesgo, including icons by Flaticon, and
infographics & images by Freepik.

Thanks!

Please keep this slide for attribution.

media

CMU Unit 3.2.3:

Looping

through Group

Children

AKA Iteration

START!

Show answer

Auto Play

Slide 1 / 28

SLIDE