无法在功能中定义用户输入

问题描述 投票:1回答:3

我正在跟踪微软对edX初学者的Python课程的介绍,我在他们的第二个模块中遇到了麻烦,他们要求你创建一个函数,将“Doctor”标题添加到用户输入的名称。

这是他们提供的建议:

  • 定义带有参数名称的函数make_doctor()
  • 获取变量full_name的用户输入
  • 使用full_name作为参数调用该函数
  • 打印返回值
  • 使用用户输入的full_name参数创建并调用make_doctor() - 然后打印返回值

这是我到目前为止:

def make_doctor(name):
full_name = print("Doctor" + input().title())
return full_name

print(name)

非常感谢任何帮助。

python azure jupyter
3个回答
1
投票

Python是一个off-side rule language

Python参考手册(link

在逻辑行开头的前导空格(空格和制表符)用于计算行的缩进级别,而后者又用于确定语句的分组。

与诸如大括号语言之类的其他语言相比,缩进(通常)不具有风格,但是为了对语句进行分组是必需的。因此,您的代码应如下所示:

def make_doctor(name):
    return "Doctor" + name


full_name = input()
print(make_doctor(full_name))

0
投票
def make_doctor(name):
    # add the Doctor title to the name parameter
    d_name = 'Doctor '+name
    # print the return value
    print(d_name)
    return d_name

# get the user input for the variable full_name
full_name=input('Enter your full name: ')
# pass full_name as an argument to make_doctor function
doc = make_doctor(full_name)
# print return value
print(doc)

0
投票
    def make_doctor(name):
        full_name = input()
    return full_name

    print('Doctor ' + full_name)
© www.soinside.com 2019 - 2024. All rights reserved.