if/elif语句出现语法错误,不确定是什么导致

2024-04-26 15:04:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在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

Tags: orselfrightif错误random语句width
1条回答
网友
1楼 · 发布于 2024-04-26 15:04:21

我认为你的语法在以下方面是无效的:

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

相关问题 更多 >