Menu
CoddyTech

Recap: Notification Channels

Lesson 42 of 48 in Coddy's Python for GDScript Developers course.

challenge icon

Challenge

Beginner

Implement Email.send(text) returning email: plus text and Sms.send(text) returning sms: plus text. Implement Dispatcher(channels) storing a copy of the supplied list, and dispatch(text) returning one result per channel in order. Input has a space-separated line of channel names (email, sms, or log), then the message. The locked driver supplies the log channel with the same send API, creates the dispatcher, clears the original channel list, and prints dispatched results. With no channels, print none. Repeated channels produce repeated results. These methods format strings only; they never send real messages.

The locked driver handles input and output. Submit only the required class and function definitions with the exact API names. Do not read input or print from your classes.

Your code goes in the editable files email.py and sms.py and dispatcher.py. driver.py holds the supplied input/output code and API checks and cannot be edited. Keep the supplied imports; do not read input or print from the editable modules.

Try it yourself

from email import Email
from sms import Sms
from dispatcher import Dispatcher

class Log:
    def send(self, text):
        return "log:" + text

factories = {"email": Email, "sms": Sms, "log": Log}
channels = [factories[name]() for name in input().split()]
text = input()
dispatcher = Dispatcher(channels)
channels.clear()
results = dispatcher.dispatch(text)
if not results:
    print("none")
for result in results:
    print(result)

All lessons in Python for GDScript Developers

Practice on your own: Online Python compiler