python三只乌龟赛跑,不会做,就是用海龟作图画出三只乌龟,和几条跑道,然后比赛赛跑
import turtle as t
import random as rd
import time
t.tracer(5)
x,y = -225,-200
t.bgcolor("black")
t.color("white")
t.pensize(5)
t.seth(90)
t.ht()
for i in range(4):
t.up()
t.goto(x,y)
t.down()
x = x+150
for j in range(20):
t.fd(10)
t.up()
t.fd(10)
t.down()
T0 = t.Turtle()
T0.up()
T0.shape("turtle")
T0.shapesize(2)
T0.seth(90)
T1 = T0.clone()
T2 = T0.clone()
T0.goto(-150,-200)
T1.goto(0,-200)
T2.goto(150,-200)
t.update()
x0,y0 = -150,-200
x1,y1 = 0,-200
x2,y2 = 150,-200
T0.color("red")
T1.color("blue")
T2.color("yellow")
while True:
if y0 <=200 and y1 <=200 and y2 <=200 :
speed_0 = rd.randint(3,8)
speed_1 = rd.randint(3,8)
speed_2 = rd.randint(3,8)
y0 = y0+speed_0
y1 = y1+speed_1
y2 = y2+speed_2
T0.goto(x0,y0)
T1.goto(x1,y1)
T2.goto(x2,y2)
time.sleep(0.05)
else:
print("红色乌龟最后位置:(",x0,",",y0,")")
print("蓝色乌龟最后位置:(",x1,",",y1,")")
print("黄色乌龟最后位置:(",x2,",",y2,")")
break
t.done()