I am studying how to use conditions in Python and I have no idea why on earth there’s a syntax error in my code, when I have just written normal condition:
else y>200:
Here is my code:
import tkinter
from random import *
canvas=tkinter.Canvas(width=400, height=400)
canvas.pack()
canvas.create_line(0, 200, 400, 200)
def utvar(suradnice):
x=suradnice.x
y=suradnice.y
if y<200:
canvas.create_rectangle(x, y, x+30, y+30, fill='blue')
else y>200: #invalid syntax error is there between else and y
canvas.create_oval(x-15, y-15, x+15, y+15, fill='yellow')
canvas.bind('<Button-1>', utvar)
Advertisement
Answer
The
else y>200:
should be
elif y>200:
You can look into the documentation for if statements: if Statements