我正在尝试创建花朵,但是当我调用draw_petal(brad
时,循环并没有形成。
我执行以下操作:
import turtle
def draw_petal(some_turtle):
for i in range(1,3):
some_turtle.forward(200)
some_turtle.right(60)
some_turtle.forward(200)
some_turtle.right(120)
def draw_flower():
window = turtle.Screen()
window.bgcolor("yellow")
#create a turtle brad - draws a flower.
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("black")
brad.speed(2)
for i in range(1,37):
draw_petal(brad)
brad.right(10)
window.exitonclick()
draw_flower()
我希望乌龟向右转10度并形成36次循环。
答案 0 :(得分:0)
解决了。问题是window.exitonclick()在for中 循环。
能够解决您的问题真是太好了!像这样的乌龟程序的典型布局大致是:
from turtle import Screen, Turtle
def draw_petal(some_turtle):
for _ in range(2):
some_turtle.forward(200)
some_turtle.right(60)
some_turtle.forward(200)
some_turtle.right(120)
def draw_flower():
""" Create a turtle named brad; draw a flower. """
brad = Turtle("turtle")
brad.color("black")
brad.speed('slow')
for _ in range(36):
draw_petal(brad)
brad.right(10)
brad.hideturtle()
window = Screen()
window.bgcolor("yellow")
draw_flower()
window.exitonclick()