반응형
Kids drink toddy.
Teens drink coke.
Young adults drink beer.
Adults drink whisky.
Make a function that receive age, and return what they drink.
Rules:
Children under 14 old.
Teens under 18 old.
Young under 21 old.
Adults have 21 or more.
Examples: (Input --> Output)
13 --> "drink toddy"
17 --> "drink coke"
18 --> "drink beer"
20 --> "drink beer"
30 --> "drink whisky"
Solution:
DRINKS = {
"Children": "toddy",
"Teens": "coke",
"Young": "beer",
"Adults": "whisky",
}
def get_age_type(func):
def wrapper(age, age_type=""):
if age < 14:
age_type = "Children"
elif age < 18:
age_type = "Teens"
elif age < 21:
age_type = "Young"
else:
age_type = "Adults"
return func(age_type)
return wrapper
@get_age_type
def people_with_age_drink(age_type: str) -> str:
return f"drink {DRINKS[age_type]}"
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1010. Double Char (0) | 2022.10.10 |
---|---|
1009. Surface Area and Volume of a Box (0) | 2022.10.10 |
1007. Volume of a Cuboid (0) | 2022.10.08 |
1006. Filter out the geese (0) | 2022.10.06 |
1005. Palindrome Strings (0) | 2022.10.05 |