在在线课程练习中发现错误

时间:2019-05-07 20:40:46

标签: python

我刚刚开始从在线课程中学习python,这是他们在其页面上发布的示例之一。

修复错误

def make_greeting(name, greeting = "Hello"):
    return (greeting + " " + name + "!")

# get name and greeting, send to make_greeting 
print(make_greeting(get_name(), get_greeting()))

def get_name():
    name_entry = input("enter a name: ")
    return name_entry

def get_greeting():
    greeting_entry = input("enter a greeting: ")
    return greeting_entry

2 个答案:

答案 0 :(得分:-1)

def make_greeting(name, greeting = "Hello"): 
     return (greeting + " " + name + "!")

# get name and greeting, send to make_greeting

def get_name(): 
    name_entry = input("enter a name: ") 
    return name_entry

def get_greeting(): 
    greeting_entry = input("enter a greeting: ") 
    return greeting_entry

print(make_greeting(get_name(), get_greeting()))

答案 1 :(得分:-1)

这是其他人的答案的简化版本,使用您使用的一线功能。

def get_name(): return input("enter a name: ")

def get_greeting(): return input("enter a greeting: ") 

def make_greeting(name, greeting = "Hello"): return (greeting + " " + name + "!")

print(make_greeting(get_name(), get_greeting()))