daco2020 2022. 10. 8. 15:26

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]}"