【发布时间】:2021-09-30 15:36:02
【问题描述】:
我不知道我的代码哪里出了问题,我正在尝试一切:(
这是代码,感谢大家的帮助! :)
import turtle
def main():
print("Project 1 by Amanda Basant")
main()
def draw_filled_square(turtle,size,color):
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(4):
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
def draw_picture():
window = turtle.Screen()
amanda = turtle.Turtle()
amanda.up()
amanda.goto(0,0)
amanda.down()
draw_filled_square(amanda,300,"blue")
draw_filled_square(amanda,300,"green")
draw_picture()
我想最终画出enter image description here这个。我解决了我最初遇到的问题。我可以在盒子上写字母,但我现在在如何填满盒子和和乌龟一起跑方面很挣扎。有谁知道为什么这些盒子不会填满?
【问题讨论】:
-
你现在遇到了什么错误?
-
你的缩进看起来不对,我认为
for循环应该嵌套在你的draw_filled_square函数中? -
我收到一个错误,说尺寸未定义,让我试试
-
我嵌套了 for 循环,现在我收到一条错误消息,提示“未定义蓝色”
-
简单的
blue会变成变量,使用引号,"blue"表示字符串。绿色也一样。
标签: python turtle-graphics python-turtle