반응형
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}!"
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1003. Find the Remainder (0) | 2022.10.03 |
---|---|
1002. Twice as old (0) | 2022.10.03 |
0930. Count of positives, sum of negatives (0) | 2022.09.30 |
0929. Summing a number's digits (0) | 2022.09.29 |
0928. Grasshopper - Terminal game combat function (0) | 2022.09.28 |