Calvin (Deutschbein)
W1D3: 30 Aug
Define |
Use |
---|---|
Format:
Example: def turn_right():
turn_left()
turn_left()
turn_left()
|
Format:
|
def fill_pothole():
turn_right()
move()
put_beeper()
turn_left()
turn_left()
move()
turn_right()
def main():
move()
fill_pothole()
move()
move()
fill_pothole()
move()
|
def fill_pothole():
# Places a beeper to Karel's right and returns
def fill_pothole():
""" Two
lines"""
def fill_pothole():
turn_right() # face pothole
move() # go to pothole
put_beeper() # place "tar"
turn_left() # reverse 1/2
turn_left() # reverse 2/2
move() # exit pothole
turn_right() # return to original direction
def turn_right():
turn_left() # turn right 1/3
turn_left() # turn right 2/3
turn_left() # turn right 3/3
def turn_right():
for i in range(3): # do something 3 times
turn_left() # the thing to do 3 times
for j in range(n):
# statements to be repeated
Karel is a good listener and can answer the following questions:
front_is_clear()
| front_is_blocked()
|
left_is_clear()
| left_is_blocked()
|
right_is_clear()
| right_is_blocked()
|
beepers_present()
| no_beepers_present()
|
facing_north()
| not_facing_north()
|
facing_south()
| not_facing_south()
|
facing_east()
| not_facing_east()
|
facing_west()
| not_facing_west()
|
This is listed in the Karel Supplement - you may want to bookmark it for now.
Karel can answer, how can we ask?
no_beepers_present()
put_beeper()
if beepers_present():
put_beeper()
def fill_and_move():
if beepers_present():
put_beeper()
move()
def main():
for k in range(4):
fill_and_move()
|
Karel can answer, how can we ask?
front_is_clear()
fill_and_move()
while front_is_clear():
fill_and_move()
def fill_and_move():
if beepers_present():
put_beeper()
move()
def main():
while front_is_clear():
fill_and_move()
|