0 10 20 30 40 50 60 70 80 90 100 99125 0
import turtle import random # keep asking the user to enter player names def get_player_names(): names = [] print("Player names:") print("=============") while True: name = input("Please enter a player name (or leave empty to finish):") if name == "": return names names.append(name) # make a turtle for each player def create_turtles(player_names): turtles = [] y = 0 for i in range(len(player_names)): t = turtle.Turtle() turtles.append(t) t.pu() t.goto(-100, y) t.pd() t.write(player_names[i]) y+=50 return turtles # make each turtle move randomly forward until one wins def race(turtles): while True: for i in range(len(turtles)): turtles[i].forward(random.randint(1,10)) if turtles[i].pos()[0] > 100: return i # main code starts here players = get_player_names() turtles = create_turtles(players) winner = race(turtles) print(players[winner], "wins!") # Challenges: # 1) Draw a finish line (where x = 100) # 2) Make each turtle a different colour # 3) Draw different lanes for each turtle to race in
You are not logged in
`¬
1!
2"
3£
4$
5%
6^
7&
8*
9(
0)
-_
=+
TAB
Q
W
E
R
T
Y
U
I
O
P
[{
]}
ENTER
CAPS
A
S
D
F
G
H
J
K
L
;:
'@
#~
ENTER
SHIFT
\|
Z
X
C
V
B
N
M
,<
.>
/?
SHIFT
 
SPACE
 
0 WPM
0%
0s
0%