Python TypeError:在*之后的type对象参数必须是iterable,而不是int
我正在创建一个海龟程序,它将画一棵圣诞树和一些小装饰品。我希望这些小玩意儿有随机的颜色,并在圣诞树上随机点。这是我的代码:Python TypeError:在*之后的type对象参数必须是iterable,而不是int,python,typeerror,turtle-graphics,Python,Typeerror,Turtle Graphics,我正在创建一个海龟程序,它将画一棵圣诞树和一些小装饰品。我希望这些小玩意儿有随机的颜色,并在圣诞树上随机点。这是我的代码: turtle.goto(random.randint(1,8)),(random.randint(1,8)) 但是,当我运行程序时,会出现以下错误: TypeError:在*之后的type对象参数必须是iterable,而不是int 我如何解决这个问题?我不知道海龟的情况,但我最好的猜测是你的括号有问题: turtle.goto(random.randint(1,8)),
turtle.goto(random.randint(1,8)),(random.randint(1,8))
但是,当我运行程序时,会出现以下错误:
TypeError:在*之后的type对象参数必须是iterable,而不是int
我如何解决这个问题?我不知道海龟的情况,但我最好的猜测是你的括号有问题:
turtle.goto(random.randint(1,8)),(random.randint(1,8))
# Extra closing parenthesis ^,^ extra opening
将其更改为:
turtle.goto(random.randint(1,8), random.randint(1,8))
goto
接受一个x
和一个可选的y
turtle.goto(x,y=None)
如果我们有
x = random.randint(1,8)
y = random.randint(1,8)
我们可以做
turtle.goto(x, y)
或者一次过,为可读性留出一些空间,增加发现错误的机会,尽可能少地使用大括号
turtle.goto( random.randint(1,8), random.randint(1,8) )
您不需要在给
goto
的值周围添加额外的参数goto
和randint()
中的括号有问题。您可以显示函数的定义吗goto
?