if / elif语句中的语法错误,不确定导致错误的原因

时间:2016-03-28 17:31:17

标签: python if-statement python-3.5

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

1 个答案:

答案 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