我怎么能把这个作为论点呢?

2024-04-25 22:27:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想画一个南瓜灯,但我不知道如何应用我定义的这些参数。。。有什么功能可以让我随意画出我创造的形状?你知道吗

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()

Tags: 参数size定义deffatcolorsmallshape
1条回答
网友
1楼 · 发布于 2024-04-25 22:27:31

一些修复程序将解决此问题:

from turtle import *

canvas = Screen()
canvas.setup(400,200)

pumpkin_size = raw_input("Would you like your pumpkin to be tall, fat, or small? ")
turtle = Turtle()

print 'selection {}'.format(pumpkin_size)


def tall_pumpkin():
    turtle.color("orange")
    turtle.shape("circle")
    turtle.shapesize(20,16,5)
    turtle.fillcolor("orange")


def fat_pumpkin():
    turtle.color("orange")
    turtle.shape("circle")
    turtle.shapesize(15,18,5)


def small_pumpkin():
    turtle.color("orange")
    turtle.shape("circle")
    turtle.shapesize(14,14,5)

interpret_size = {
    "fat": fat_pumpkin,
    "tall": tall_pumpkin,
    "small": small_pumpkin,
    }

interpret_size[pumpkin_size]()
canvas.exitonclick()

首先您需要声明一个canvas对象,然后使用"fat": fat_pumpkin而不是"fat": "fat_pumpkin"现在您可以调用interpret_size[pumpkin_size](),它将从输入中调用键处的函数。你知道吗

还有一件事是使用turtle实例并设置它自己的属性,如colorshape。你知道吗

  • 对于python3用户input()

相关问题 更多 >