我正在设置两个定义,我希望从 drawBar 中读取填充颜色。程序未读取与该值对应的正确颜色。
import turtle
wn = turtle.Screen() # Set up the window
wn.bgcolor("white")
tess = turtle.Turtle()
tess.penup()
tess.goto(-100,-75)
tess.pendown()
def drawBar(t, height):
""" Get turtle t to draw one bar, of height. """
t.left(90)
t.begin_fill()# Point up
t.forward(height)
# Draw up the left side
t.right(90)
t.forward(40) # width of bar, along the top
t.right(90)
t.forward(height)
t.end_fill()# And down again!
t.left(90)
def drawColor(t, height):
drawBar(t, height)
if height >= 200:
return tess.fillcolor("red")
elif height < 200 and v >= 100:
return tess.fillcolor("yellow")
elif height < 100:
return tess.fillcolor("green")
xs = [48, 117, 200, 240, 160, 260, 220]
for v in xs: # assume xs and tess are ready
drawColor(tess, v)
我不知道为什么这不起作用。