【发布时间】:2015-04-13 14:47:45
【问题描述】:
我正在上高中计算机科学课,我似乎无法找到正确的放置/使用 turtle.begin_fill() 和 turtle.end_fill() 来为我正在绘制的形状着色。我试过移动这两个,但我一直收到这个错误:
TypeError: begin_fill() takes 1 positional argument but 2 were given
这是我的代码:
side_number = int(input("How many sides should the polygon have?"))
side_length = int(input("How long should the sides be?"))
side_color = (input("What color should the sides be?"))
fill_color = (input("What color should fill the shape?"))
import turtle
wn = turtle.Screen()
john = turtle.Turtle()
john.color(side_color)
for i in range(side_number):
john.begin_fill(fill_color)
john.forward(side_length)
john.left(360/side_number)
john.end_fill(fill_color)
【问题讨论】:
-
...
turtle.begin_fill不接受任何参数(隐式的第一个self参数除外)。你期待fill_color做什么? -
用颜色填充绘制的形状。我是否误解了它的功能是什么?我正在使用的教程没有解释 begin.fill 和 end.fill 的作用,但作业要求使用它们。我将如何用颜色填充形状?
-
begin_fill给解释器发信号,“嘿,我要开始画一个形状了”,end_fill给解释器发信号,“嘿,我画完了形状,请填写现在”。只需使用这两个就足够了,前提是您事先指定填充颜色并在正确的时间调用它们,如我的帖子中所述 -
@RialJohnson 是的,可能。您为什么不尝试阅读我刚刚链接的文档?
-
@Kevin 谢谢你的解释解决了很多困惑!
标签: python colors turtle-graphics