gpt4 book ai didi

python - 我在 python 2.7 中用循环搞乱 turtle 导入, turtle 不会移动

转载 作者:太空宇宙 更新时间:2023-11-04 04:55:47 25 4
gpt4 key购买 nike

我在 python 2.7 中用循环搞乱 turtle 导入,我只看到屏幕闪烁,程序退出。这是我的代码:

import turtle

colors = ["red", "orange", "yellow", "green", "blue", "purple"]
dColors = dict(enumerate(colors))


def circleOfShapes(aTurtle):
edges = 3
radius = 100
for i in range(5):
for k in range(360 / 5):
aTurtle.color(dColors.get(i))
aTurtle.circle(radius, None, edges)
aTurtle.right(5)
edges += 1
radius -= 10


turt = turtle.Turtle()
turt.shape("arrow")

window = turtle.Screen()
window.bgcolor("white")
window.exitonclick()

circleOfShapes(turt)

这只是我想为我的 child 做一些很酷的东西,让他像我希望的那样在很小的时候就对编程产生兴趣。感谢您的帮助。

最佳答案

对我而言,代码运行良好。唯一的问题是在您的 for 循环中,您试图在第 11 行中使用 float 进行循环。您需要使用整数。你可以施放它。那应该解决它。希望这会有所帮助。

编辑:代码的另一个问题是 window.exitonclick()

删除或注释掉

关于python - 我在 python 2.7 中用循环搞乱 turtle 导入, turtle 不会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47106291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com