我在if语句中遇到语法错误,我不确定为什么我会收到错误。有人可以帮忙吗?
def draw_square(self, loc, width):
loc = (x, y)
for i in range (3):
width(width)
turtle.forward(60)
turtle.right(90)
turtle.forward(random.randint(10,100))
turtle.right(90)
turtle.forward(60)
turtle.right(90)
turtle.forward(random.randint(10, 100))
if turtle.xcor < or > x:
x = turtle.xcor
elif turtle.ycor < or > y:
y = turtle.ycor
return self.loc, self.width
答案 0 :(得分:1)
认为您的语法无效:
if turtle.xcor < or > x:
x = turtle.xcor
elif turtle.ycor < or > y:
y = turtle.ycor
尝试将其更改为:
if turtle.xcor < x or turtle.xcor > x:
x = turtle.xcor
elif turtle.ycor < y or turtle.ycor > y:
y = turtle.ycor