2024-10-05 10:38:17 发布
网友
我正在创建一个海龟计划,将画一棵圣诞树和一些装饰品。我希望圣诞饰品有随机的颜色,去随机点在圣诞树上。这是我的代码:
turtle.goto(random.randint(1,8)),(random.randint(1,8))
但是,当我运行程序时,出现以下错误:
TypeError: type object argument after * must be an iterable, not 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和一个可选的yturtle.goto(x, y=None)
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的值周围不需要额外的paraen。
我不知道海龟的事,但我最好的猜测是你的括号有问题:
更改为:
goto
接受一个x
和一个可选的y
turtle.goto(x, y=None)
如果我们有
我们可以的
或者一次性地,用一些空格来表示可读性和发现错误的额外机会,用尽可能少的大括号
在给
goto
的值周围不需要额外的paraen。相关问题 更多 >
编程相关推荐