-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6-exercises.py
105 lines (81 loc) · 1.72 KB
/
day6-exercises.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
## Day 6 - Beginner | Functions & Karel
## 03.06.2023
## Exercises
## These script should be run on https://reeborg.ca/reeborg.html
## Exercise - 1: Turn Around
def turn_around():
turn_left()
turn_left()
move()
move()
turn_around()
move()
move()
turn_around()
## Exercise - 2 Turn Right
def turn_right():
turn_left()
turn_left()
turn_left()
def four_square_move():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_right()
move()
turn_around()
four_square_move()
## Exercise - 3 Hurdles Loop Challenge
## https://reeborg.ca/reeborg.html?lang=en&mode=python&menu=worlds%2Fmenus%2Freeborg_intro_en.json&name=Hurdle%201&url=worlds%2Ftutorial_en%2Fhurdle1.json
def hurdle1_challenge_step():
move()
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
for jump in range(6):
hurdle1_challenge_step()
## Exercise 4- While Loop
number_of_hurdles = 6
while number_of_hurdles > 0 :
hurdle1_challenge_step()
number_of_hurdles -= 1
## Hurdle2 - challenge (randomly change of finish Hurdle1)
while at_goal() != True: ## while not at_goal():
hurdle1_challenge_step()
## Hurdle3 - challenge
def hurdle_step():
turn_left()
move()
turn_right()
move()
turn_right()
move()
turn_left()
while not at_goal():
if wall_in_front():
hurdle_step()
else:
move()
## Hurdle4 - challenge
def modified_hurdle_step():
turn_left()
while wall_on_right():
move()
turn_right()
move()
turn_right()
while front_is_clear():
move()
turn_left()
while not at_goal():
if wall_in_front():
modified_hurdle_step()
else:
move()