[英]How to pass variable to function
我不知道我的代碼哪里出了問題,我正在嘗試一切:(
這是代碼,感謝大家的幫助::)
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()
我想在這里最終繪制輸入圖像描述。 我解決了最初的問題。 我可以寫盒子上的字母,但我現在在如何填滿盒子和與烏龜一起跑方面苦苦掙扎。 有誰知道為什么盒子不會填滿?
盒子沒有被填滿的原因是turtle.end_fill()
在raw_filled_square()
function 之后,而不是 function 的最后一行。你沒有得到兩個盒子的原因是你在上面畫了一個另一個。 讓我們稍微修改一下這段代碼,讓它從你想要的圖像中繪制方框:
from turtle import Screen, Turtle
def main():
print("Project 1 by Amanda Basant")
screen = Screen()
draw_picture()
screen.exitonclick()
def draw_filled_square(turtle, size, color):
turtle.fillcolor(color)
turtle.begin_fill()
for _ in range(4):
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
def draw_picture():
amanda = Turtle()
for _ in range(2):
draw_filled_square(amanda, 300, "green")
amanda.right(90)
draw_filled_square(amanda, 300, "blue")
amanda.right(90)
main()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.