-
Notifications
You must be signed in to change notification settings - Fork 1
/
Waves.py
53 lines (41 loc) · 1.26 KB
/
Waves.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from karel.stanfordkarel import *
"""
diagnostic problem
Write a program that has Karel draw four small "waves". Each wave is a triangle made up of three beepers. There is a gap between each wave.
This problem reviews basic control flow with Karel. It was much easier to solve if you defined a make_wave() function. It also introduces a fence-post problem where you need to move between waves three times, but you need to draw four waves.
"""
def main():
# make the first three waves
for i in range(3):
build_wave()
# you need to move twice to go between waves
move()
move()
# because of the fencepost bug, we need a fourth wave
build_wave()
def build_wave():
put_beeper()
move()
put_beeper()
turn_left()
move()
put_beeper()
turn_around()
move()
turn_left()
def turn_around():
turn_left()
turn_left()
# Example Solution 2
# def main():
# # you can also solve this problem with a while loop
# while front_is_clear():
# build_wave()
# # you might be facing a wall at this point!
# if front_is_clear():
# move()
# move()
# def build_wave():
# same as in solution 1
if __name__ == "__main__":
run_karel_program('Roomba2.w')