나는 이렇게 학습한다/Algorithm & SQL

1001. Hello, Name or World!

daco2020 2022. 10. 2. 00:05
반응형

Define a method hello that returns "Hello, Name!" to a given name, or says Hello, World! if name is not given (or passed as an empty String).

Assuming that name is a String and it checks for user typos to return a name with a first capital letter (Xxxx).

Examples:

* With `name` = "john"  => return "Hello, John!"
* With `name` = "aliCE" => return "Hello, Alice!"
* With `name` not given 
  or `name` = ""        => return "Hello, World!"



Solution:

def modify_capitalize(func):
    def wrapper(name=""):
        return func(name.capitalize() or "World")
    return wrapper

@modify_capitalize
def hello(name):
    return f"Hello, {name}!"


반응형