Jed Rembold
January 16, 2026
eTRF9
Karel starts as shown to the right with 20 beepers in its bag. After executing the commands below, how many beepers are left in the bag upon the conclusion of the program?
while left_is_clear():
while front_is_clear():
move()
if no_beepers_present():
put_beeper()
turn_left()
import karel
def main():
"""Follows a path of beepers as best as possible from one end of the
world to the other end.
"""
while front_is_clear():
follow_straight_beeper_path()
determine_next_direction()
def follow_straight_beeper_path():
"""Follows a beeper path until no beeper
is found, then doubles back to last beeper
space"""
while beepers_present():
if front_is_clear():
move()
if front_is_clear():
turn_around()
move()
def determine_next_direction():
"""Determines the direction of the next path of beepers. Tries one direction
and if it finds no beeper there it knows it must be the other direction.
Leaves Karel facing the next path of beepers.
"""
turn_left()
if front_is_clear():
move()
if beepers_present(): # This side! I'm reseting here but probably don't need to
turn_around()
move()
turn_around()
else: # No beepers, so must be the other direction
turn_around()
move()
def turn_around():
"""Turns Karel 180"""
turn_left()
turn_left()