BYU logo Computer Science

To start this assignment, download this zip file.

The following guide pages cover material needed for this assignment:

Homework 2a — If

1. Invert

Bit needs to turn blue squares white, and turn white squares blue. For example, if Bit starts in this world:

a world with one green square on the left and some blue squares all in the middle row seperated by random white squares, bit starting on the green square

then the final world needs to look like this:

blue and white squares reversed, bit ending on the right of the middle row

To check if a square is empty, use:

bit.is_on_white()

To erase the color in any square, use:

bit.paint('white')

Use the starter code in invert.py to write your code.

Be sure to check all three worlds! You will also see a world called invert2:

the same type of world, but with a different pattern of blue and white squares

and a world called invert-careful. Note that the red squares are not converted, but white squares are turned to blue:

a world with two green squares, one red square, and some blue squares in the middle row, spaced randomly, bit starting on the left in the middle row

2. Wander

Bit starts in this world:

a world with some green and blue squares, placed randomly with bit in the bottom left

Bit follows these rules:

  • Bit moves until it’s blocked in front
  • Bit turns left when encountering a green square
  • Bit turns right when encountering a blue square
  • Bit paints empty squares red

The final world should look like this:

Bit's path is painted red, excluding the green and blue squares, bit ending in the leftmost column in the second row from the bottom

Use the starter code in wander.py to write your code.

Be sure to check both worlds! You will see a second world called wander2:

a different world with some green and blue squares, bit in the bottom left

3. Fix the pipe

Bit is inside of a pipe and wants to patch the holes. The starting world looks like this:

A world 3 squares tall, Bit starting in the middle row, with black squares in the top and bottom row with some empty spaces

Bit patches the holes with blue sealant. So when Bit is finished, the world should look like this:

The empty spaces in the top and bottom row of the previous world have been changed to blue, bit ending on the right in the middle row

Use the starter code in fix_pipe.py to write your code.

Grading

ActivityPoints
invert.py5
wander.py5
fix_pipe.py10

Manual Grading

Refer to the Quality Code guide page for detailed explanations and examples on each of these rubric criteria.

Intent

The intent of this assignment is for you to correctly use if-else statements.

You should not have if and else branches that do the same thing.
We do not expect you to use concepts like or, and, or break.
Do not use while-else. Simply write code after/outside the while loop.

RubricPoints
Whitespace1
Naming1
Decomposition4
Intent4
Total10