Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Dialogues by tom-tom
VOWELS = "aeiouAEIOU"
class Chat:
def __init__(self):
self._dialogue = []
def _connect(self, interlocutor):
interlocutor.set_chat(self)
connect_human = _connect
connect_robot = _connect
def add_message(self, interlocutor, message):
self._dialogue.append((interlocutor, message))
def _show_dialogue(self, transform):
return '\n'.join(f'{interlocutor.name} said: {transform(message)}'
for interlocutor, message in self._dialogue)
def show_human_dialogue(self):
return self._show_dialogue(lambda x: x)
def show_robot_dialogue(self):
return self._show_dialogue(lambda x: ''.join('0' if c in VOWELS else '1' for c in x))
class Interlocutor:
def __init__(self, name):
self.name = name
def set_chat(self, chat):
self._chat = chat
def send(self, message):
self._chat.add_message(self, message)
Human = Interlocutor
Robot = Interlocutor
Jan. 15, 2019
Comments: