I have an assignment which is asked to set two turtles in a race track (same size but separate track). I am able to make them move, but the second one moves only when the first one moved a half of the track. I'm not sure how to make the turtles move at the same time. Here is my code:
import turtle
import random
import time
wn = turtle.Screen()
wn.bgcolor("lightgreen")
t = turtle.Turtle()
t.shape('turtle')
t.color('red')
t2 = turtle.Turtle()
t2.shape('turtle')
t2.color('blue')
#user input function
p = float(input('please insert the perimeter:'))
#set the track
def drawTrack(p,r):
shortside = (p/2.0)/(r+1)
longside = r*shortside
turtle.setup((shortside*2)+60, longside +40)
t.penup()
t2.penup()
t.setposition(-shortside-10, -longside/2)
t2.setposition(10, -longside/2)
for i in range (2):
#first track
t.speed(1)
t.pendown()
t.forward(shortside)
t.left(90)
t.forward(longside)
t.left(90)
#second track
t2.speed(1)
t2.pendown()
t2.forward(shortside)
t2.left(90)
t2.forward(longside)
t2.left(90)
drawTrack(p,2)
wn.exitonclick()