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:
JavaScript
x
17
17
1
import tkinter
2
from random import *
3
canvas=tkinter.Canvas(width=400, height=400)
4
canvas.pack()
5
6
canvas.create_line(0, 200, 400, 200)
7
8
def utvar(suradnice):
9
x=suradnice.x
10
y=suradnice.y
11
if y<200:
12
canvas.create_rectangle(x, y, x+30, y+30, fill='blue')
13
else y>200: #invalid syntax error is there between else and y
14
canvas.create_oval(x-15, y-15, x+15, y+15, fill='yellow')
15
16
canvas.bind('<Button-1>', utvar)
17
Advertisement
Answer
The
JavaScript
1
2
1
else y>200:
2
should be
JavaScript
1
2
1
elif y>200:
2
You can look into the documentation for if
statements: if
Statements