Teacher's Guide
Chapter 6 / Level 6: Alternate Loop Conditions
Teaching Objective:
- Student learns how to set up loops with multiple conditions
- Learns how to consolidate multiple strips of code into a single loop
- Understands how conditions and loops can be used to optimize code
Guide
In this level the student must grab all the berries so they can be combined into Jam by using loop conditions. Create a list named berries so that you may store the different types of berries before combining them all at the end of the level.
Set up a for loop and have it cycle three (3) times one for each edge of the courtyard that’s lined with berries. There are three (3) different types of berries in the courtyard, each with different quantities: 3 red berries , 5 blue berries and 4 black berries (the purple berries).
for x in range(3):
player.move_forward(4)
if x == 0:
red_berries = 3
berries.append(red_berries)
if x == 1:
blue_berries = 5
berries.append(blue_berries)
if x == 2:
black_berries = 4
berries.append(black_berries)
player.turn_left()
else:
player.move_forward(4)
player.combine(berries)
Since each edge has the same type of berry, set up conditions for each loop cycle. Have the loops test to see what cycle they are currently at and store the number of berries of that type you’ve collected in a variable. Use the append() the value to the list, for example:
blue_berries = 5
berries.append(blue_berries)
Once you’re done adding all the values to the list us the else statement to rap up the loop and have the player make their way to the X mark and use the combine() function to mix all the berries into jelly. Once this is done, you have successfully finished this level’s exercise.
Map overview and path

Code Solution
import player
berries = []
player.turn_right()
for x in range(3):
player.move_forward(4)
if x == 0:
red_berries = 3
berries.append(red_berries)
if x == 1:
blue_berries = 5
berries.append(blue_berries)
if x == 2:
black_berries = 4
berries.append(black_berries)
player.turn_left()
else:
player.move_forward(4)
player.combine(berries)T