我想画一个南瓜灯,但我不知道如何应用我定义的这些参数。。。有什么功能可以让我随意画出我创造的形状?你知道吗
from turtle import*
pumpkin_size=input("Would you like your pumpkin to be tall, fat, or small? ")
turtle_1=Turtle()
turtle_2=Turtle()
def tall_pumpkin():
color("orange")
shape("circle")
shapesize(20,16,5)
fillcolor("orange")
def fat_pumpkin():
color("orange")
shape("circle")
shapesize(15,18,5)
def small_pumpkin():
color("orange")
shape("circle")
shapesize(14,14,5)
interpret_size = {
"fat": "fat_pumpkin",
"tall": "tall_pumpkin",
"small": "small_pumpkin",
}
exitonclick()
一些修复程序将解决此问题:
首先您需要声明一个canvas对象,然后使用
"fat": fat_pumpkin
而不是"fat": "fat_pumpkin"
现在您可以调用interpret_size[pumpkin_size]()
,它将从输入中调用键处的函数。你知道吗还有一件事是使用
turtle
实例并设置它自己的属性,如color
或shape
。你知道吗input()
相关问题 更多 >
编程相关推荐