BYU logo Computer Science

To start this assignment, download this zip file.

The following guide pages cover material needed for this assignment:

Lab 2b β€” Conditions

Preparation

Reminder, you should work in teams of 2 or 3 when solving the lab problems. Learning to code together is an important part of this class.

1 minute

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.

Paint the box

10 minutes

Bit’s job is to paint a green box. There are two worlds. The first world starts like this:

Bit is in a room with black walls

After Bit paints a green box, it looks like this:

a green box inside the black walls

The second world looks like this:

Bit is in an empty world

After Bit paints a green box, it looks like this:

a green box inside the empty world

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

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:

a world with red, blue, and green squares

At the end, Bit should have turned all of the blue and green squares into red ones:

all of the blue and green squares turned to red

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:

Some green squares in front of bit, some of them next to black squares

At the end, Bit should have cleared all of the green squares that are next to a black square:

All of the green squares next to black squares have been erased

Notes:

  • What is the stopping condition?
  • What conditions can Bit use to decide whether to erase a square?

Remember, use bit.paint('white') to erase a square.

Discuss with the TA:

  • Did you use two ifs or one if and one elif?
  • 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.

We are providing a solution so you can check your work. Please look at this after you complete the assignment. 😊