菜鸟在这里...需要 Python 代码结论方面的帮助

Rookie over here... Need assistance with a Python code conclusion

完成此功能以return要么 “你好,[名字]!”或“你好!” 基于输入

def say_hello(name):
    name = "Hello there!"

    assert name != "Hello there!"
    # You can print to STDOUT for debugging like you normally would
    print(name)

    # but you need to return the value in order to complete the challenge  
    return "" # TODO: return the correct value

我已经尝试了几件事,但 运行 遇到了错误,例如断言错误... 我之前已经完成了与此类似的练习测试,但我只是在这里空白。 任何有关正确代码的帮助以及您如何获得它的帮助,我们将不胜感激。

如果给出一个名称并且它不为空(“”计算结果为 False),这将填充名称

def say_hello(name=None):
    return f"Hello, {name}!" if name else "Hello there!"

assert 在这里没有多大意义。您只想根据 name 的值选择两个 return 值之一。您可以从向 name 参数添加一个默认值开始,这使调用者可以选择根本不提供名称,然后进行简单的真值测试。

def say_hello(name=None):
    if name:
        return f"Hello, {name}"
    else:
        return "Hello there!"