Jed Rembold & Fred Agbo
January 26, 2024
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()
move()
turn_left()
pick_beeper()
put_beeper()
front_is_clear()
def function_name():
# Code to be grouped
else
block is optional)if condition_test:
# Code if answer yes
else:
# Code if answer no
while condition_test:
# Code to repeat
for i in range(desired_count):
# Code to repeat
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()
int
for integers and whole
numbers
1, 2, 3, 10, 1001010101, -231
float
for numbers containing a
decimal point
1.23, 3.14, 10.001, 0.0, -8.23
complex
for numbers with an imaginary
component (which we won’t deal with)