I was coding a turtle game where when the snake goes near the "apple", it goes to a random cord and we repeat. I tried to add a go to function in python but it is not moving for some reason. I added a check to see if the if statement is happening and it is, but after the check, nothing runs. What is the problem with my code?
import turtle as t
import random
wn=t.Screen()
t.shape("turtle")
t.pu()
apple=t.Turtle()
apple.pu()
apple.shape("circle")
apple.color("red")
def forw():
t.forward(10)
def back():
t.backward(10)
wn.onkey(forw,"Up")
wn.onkey(back,"Down")
wn.onkey(lambda: t.left(45),"Left")
wn.onkey(lambda: t.right(45),"Right")
wn.listen()
if t.distance(apple)<=15 or t.distance(apple)>=-15:
print("check1")
apple.goto(random.randint(-50,50),random.randint(-50,50))