To start this assignment, download this zip file.
Lab 2b — Conditions
Preparation
5 minutes
Download the zip file for this lab, located above. This zip file has worlds that
you will use for Bit. Extract the files and put them in your cs110
directory
in a folder called lab2b
.
Exercise 1
10 minutes
Bit’s job is to paint a green box. There are two worlds. The first world starts like this:
After Bit paints a green box, it looks like this:
The second world looks like this:
After Bit paints a green box, it looks like this:
You have starter code in paint-the-box.py
.
Notes:
- Your code needs to be general enough to solve both worlds.
- Notice that Bit ends where it starts, facing the same direction.
- Think about the stopping condition — when does Bit stop painting?
- This problem does not use
and
oror
.
Discuss with the TA:
- What was your stopping condition?
- What other conditions did you need?
Red Roses
15 minutes
In this problem, Bit needs to turn all of the roses red. Here is one of the worlds:
At the end, Bit should have turned all of the blue and green squares into red ones:
You have starter code in red-roses.py
.
Notes:
- What is the stopping condition?
- What other conditions do you need?
Discuss with the TA:
- Compare your solution on this problem to the solution on the previous problem.
Clear green
15 minutes
In this problem, Bit needs to clear only the green squares that are next to the black squares. One of the worlds looks like this:
At the end, Bit should have cleared all of the green squares that are next to a black square:
Notes:
- What is the stopping condition?
- What conditions can Bit use to decide whether to erase a square?
Remember, use bit.erase()
to erase a square.
Discuss with the TA:
- Did you use two
if
s or oneif
and oneelif
? - Is there any difference?
Wrapup
5 minutes
Discuss any questions about conditions in while loops and if statements.
Grading
To finish this lab and receive a grade, take the canvas quiz.