Fred Agbo
August 31, 2026
qUhTrP

Karel starts as shown to the right. At which beeper do they end up when the below sequence of commands finishes?
while no_beepers_present():
while front_is_clear():
move()
if beepers_present():
turn_left()
else:
turn_right()
turn_left()
A good problem decomposition should mean:
import karel
def main():
# Here is our general solution with higher level of decomposition
for i in range(3):
find_next_tree()
remove_leaves()
def find_next_tree():
# the codes to find next tree
while front_is_clear():
move()
def remove_leaves():# codes to remove leaves
move_up()
deleaf()
move_down()
def move_up():
turn_left()
while right_is_blocked():
move()
def deleaf():
pick_beeper()
for i in range(3):
move()
pick_beeper()
turn_right()
turn_left()
def move_down():
while front_is_clear():
move()
turn_left()