File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 2
2
import random
3
3
screen = Screen ()
4
4
screen .setup (width = 600 ,height = 600 )
5
- screen .title ('aleena ' )
5
+ screen .title ('Turtle Race ' )
6
6
turtles = []
7
7
speed = 10
8
8
y = - 100
9
9
in_screen = True
10
+
11
+ #make turtles by appending an instance of a turtle to turtles list in an iteration
12
+ #all properties of that instance are declared inside the loop
10
13
def make_turtle ():
11
14
global y
12
15
for i in range (0 ,5 ):
@@ -19,7 +22,7 @@ def make_turtle():
19
22
t .goto (- 280 , y )
20
23
y += 50
21
24
turtles .append (t )
22
-
25
+ #move the turtle forward by a random number
23
26
def move_turtles ():
24
27
for turtle in turtles :
25
28
random_number1 = random .randint (0 ,50 )
@@ -28,11 +31,12 @@ def move_turtles():
28
31
make_turtle ()
29
32
while in_screen == True :
30
33
move_turtles ()
34
+ #iterate through turtles list and check if any has gone beyond the screen
35
+ #if so the race ends
31
36
for turtle in turtles :
32
37
xposition = turtle .xcor ()
33
38
if xposition >= 270 :
34
39
in_screen = False
40
+
35
41
36
-
37
-
38
- screen .exitonclick ()
42
+ screen .exitonclick ()
You can’t perform that action at this time.
0 commit comments