我正在跟踪微软对edX初学者的Python课程的介绍,我在他们的第二个模块中遇到了麻烦,他们要求你创建一个函数,将“Doctor”标题添加到用户输入的名称。
这是他们提供的建议:
这是我到目前为止:
def make_doctor(name):
full_name = print("Doctor" + input().title())
return full_name
print(name)
非常感谢任何帮助。
Python是一个off-side rule language:
Python参考手册(link)
在逻辑行开头的前导空格(空格和制表符)用于计算行的缩进级别,而后者又用于确定语句的分组。
与诸如大括号语言之类的其他语言相比,缩进(通常)不具有风格,但是为了对语句进行分组是必需的。因此,您的代码应如下所示:
def make_doctor(name):
return "Doctor" + name
full_name = input()
print(make_doctor(full_name))
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)
def make_doctor(name):
full_name = input()
return full_name
print('Doctor ' + full_name)