为另一个函数设置值

2024-09-27 04:25:08 发布

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

我怎么做这些功能

def InputName():
    Name = input("Name: ")
def InputCourseName():
    CourseName = input("Course: ")

设置要在中使用的名称和课程名称:

def Criacao(Name, CourseName):
    global Fonte, Output, CorTexto, Raw
    base = Image.open(Raw)
    draw = ImageDraw.Draw(base)        
    draw.text((5,5), Name.upper(), font=Fonte, fill=CorTexto)
    draw.text((6,5), CourseName.upper(), font=Fonte, fill=CorTexto)

如果我运行:Criacao(InputName(), InputCourseName()),它会工作吗?你知道吗


Tags: textnameinputbaserawdefupperfont
2条回答

你应该开始使用return

def InputName():
    name = input("Name: ")
    return name

def InputCourseName():
    courseName = input("Course: ")
    return courseName

然后可以使用返回的值来分配给局部变量

def Criacao():
    name = InputName()               # We are using the returned values here
    courseName = InputCourseName()
    global Fonte, Output, CorTexto, Raw
    base = Image.open(Raw)
    draw = ImageDraw.Draw(base)        
    draw.text((5,5), name.upper(), font=Fonte, fill=CorTexto)
    draw.text((6,5), courseName.upper(), font=Fonte, fill=CorTexto)

是的,如果您从InputName()函数返回Name,并从InputCourseName()函数返回CourseName,它将工作。你知道吗

相关问题 更多 >

    热门问题