Skip to content
Advertisement

Why does my turtle not draw my race lanes?

So I’m making a turtle race, but I wanted to make my code shorter by using def. I haven’t used it before but I looked up examples and I have no idea what my code is missing because it doesn’t work. I basically want to draw a lot of “|” but with 15 rows and 5 columns with 20 ‘spaces’ in between the columns and 35 ‘spaces’ between the rows. I don’t get any errors, the windows opens but it doesn’t draw anything. This is my code:

import turtle

lijn = turtle.Turtle()
lijn.hideturtle()
lijn.color("black")
lijn.speed(0)

fontLines = ("Arial", 16, "normal")

def line(x,y,width,text):
    lijn.penup()
    lijn.goto(x,y)
    
    for i in range (15):
        lijn.write(text, font=fontLines)
        lijn.forward(width)
    
def raceBaan():
    line(-150,60,20,"|")
    line(-150,25,20,"|")
    line(-150,-10,20,"|")
    line(-150,-45,20,"|")
    line(-150,-80,20,"|")

turtle.done()

Advertisement

Answer

yeah you just need to call raceBaan() and put that at the end of the code but before turtle.done() because you always have to call functions. Also the brackets are for parameters in case you’re wandering :)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement