Skip to content

Commit 18dc3ee

Browse files
authored
Update and rename task8.py to turtle_race.py
1 parent d84e6b7 commit 18dc3ee

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

task8.py renamed to turtle_race.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
import random
33
screen = Screen()
44
screen.setup(width=600,height=600)
5-
screen.title('aleena')
5+
screen.title('Turtle Race')
66
turtles = []
77
speed = 10
88
y = -100
99
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
1013
def make_turtle():
1114
global y
1215
for i in range(0,5):
@@ -19,7 +22,7 @@ def make_turtle():
1922
t.goto(-280, y)
2023
y+=50
2124
turtles.append(t)
22-
25+
#move the turtle forward by a random number
2326
def move_turtles():
2427
for turtle in turtles:
2528
random_number1 = random.randint(0,50)
@@ -28,11 +31,12 @@ def move_turtles():
2831
make_turtle()
2932
while in_screen==True:
3033
move_turtles()
34+
#iterate through turtles list and check if any has gone beyond the screen
35+
#if so the race ends
3136
for turtle in turtles:
3237
xposition = turtle.xcor()
3338
if xposition >=270:
3439
in_screen = False
40+
3541

36-
37-
38-
screen.exitonclick()
42+
screen.exitonclick()

0 commit comments

Comments
 (0)