mercredi 15 juillet 2020

My python turtle is on the correct coordinates for my if statement to return as true, yet my if statement is not returning as true

What I made is when the turtle is on the coordinates (0,-285), and i press the spacebar it should print 'yay', and the coordinates, otherwise it should print 'no' and the coordinates. But every time I press spacebar, it prints 'no', even when I'm on the correct coordinates. May I have some help with this?

import turtle
import time
import random
t = turtle.Pen()
t.speed(0)
check = (0,0)

x = turtle.window_width()
y = turtle.window_height()
#defining functions to move
def turn_left():
    t.left(90)
def turn_right():
    t.right(90)
def forward():
    t.forward(15)
def backward():
    t.backward(15)
def check_pos():
    check = t.pos()
    print(check)
    if check == (0,-285):
        print('yay')
    else:
        print('no')
turtle.onkeypress(turn_left, "Left")
turtle.onkeypress(turn_right, "Right")
turtle.onkeypress(forward, "Up")
turtle.onkeypress(backward, "Down")
turtle.onkeypress(check_pos, "space")
turtle.listen()

Python Shell

Aucun commentaire:

Enregistrer un commentaire