To start this assignment, download this zip file.
The following guide pages cover material needed for this assignment:
Lab 2a - If
Preparation
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 lab2a.
Exercise 1
Bit starts in this world:

(a) Can you figure out what this code does?
On a piece of scratch paper, draw out what you think the final world will look like.
from byubit import Bit
def turn_or_change(bit):
if bit.is_on_red():
bit.turn_left()
elif bit.is_on_green():
bit.paint('blue')
elif bit.is_on_blue():
bit.paint('green')
@Bit.worlds('exercise1')
def go(bit):
while bit.can_move_front():
bit.move()
turn_or_change(bit)
if __name__ == '__main__':
go(Bit.new_bit)
(b) Run the code
Inside of lab2a, run the file called exercise1.py and check your answer.
Exercise 2
Bit starts in this world:

(a) Can you figure out what this code does?
On a piece of scratch paper, draw out where you think Bit will end up. Show which square and which direction Bit will face.
from byubit import Bit
def follow_rules(bit):
if bit.is_on_blue():
bit.turn_left()
elif bit.is_on_green():
bit.turn_right()
elif bit.is_on_red():
bit.turn_right()
bit.turn_right()
@Bit.worlds('exercise2')
def go(bit):
while bit.can_move_front():
bit.move()
follow_rules(bit)
if __name__ == '__main__':
go(Bit.new_bit)
(b) Run the code
Inside of lab2a, run the file called exercise2.py and check your answer.
Fix reds
For this problem, Bit starts in this world:

Bit needs to move to the green square, and then turn all the red squares to blue:

(1) Draw the problem out. Use a drawing or a flow chart.
(2) Write the code. Use decomposition — break the problem up into multiple functions, each one doing a small thing.
Flowers
For this problem, Bit wants to grow some flowers. Bit starts in this world:

Each of the green squares represents a flower stem. Move Bit to each flower stem and grow a flower on top of it:

(1) Draw the problem out. Use a drawing or a flow chart.
(2) Write the code. Use decomposition — break the problem up into multiple functions, each one doing a small thing.
Grading
To finish this lab and receive a grade, upload a screenshot of your code to Canvas. See Lab 2a in Canvas for additional instructions.
We are providing a solution so you can check your work. Please look at this after you complete the assignment. 😊