Kodewick
Start learning →
Basic←→0 / 80

Chat effects

#009BasicFunctionsDicts5 min

The chat app can add an effect to a message. The effect functions loud and quiet are written and kept in the dict EFFECTS. Write apply_effect(text, name): take the function for that name out of the dict and use it on text. If there's no such effect, return the text unchanged.

Examples
apply_effect("Hello", "loud")→'HELLO!'
apply_effect("Good Night", "quiet")→'good night...'
main.py
def loud(text):
    return text.upper() + "!"


def quiet(text):
    return text.lower() + "..."


EFFECTS = {"loud": loud, "quiet": quiet}


def apply_effect(text, name):
    if name not in EFFECTS:
        return text
    # your code here: take this name's function from EFFECTS, use it on text and return the result
    return text
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.