Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Dialogues by OrginalS
VOWELS = "aeiouAEIOU"
class Chat:
def __init__(self):
self.messages = []
def connect_human(self, human):
human.chat = self
def connect_robot(self, robot):
robot.chat = self
def show_human_dialogue(self):
return "".join([msg + "\n" for msg in self.messages]).rstrip()
def show_robot_dialogue(self):
res = ""
for message in self.messages:
n = message.find(":")+2
msg = "".join([str(int(letter not in VOWELS)) for letter in message[n:]])
res += message[:n] + msg + "\n"
return res.rstrip()
class Human:
def __init__(self, name):
self.name = name
self.chat = None
def send(self, message):
self.chat.messages.append(f"{self.name} said: {message}")
class Robot:
def __init__(self, serial_number):
self.serial_number = serial_number
self.chat = None
def send(self, message):
self.chat.messages.append(f"{self.serial_number} said: {message}")
Oct. 6, 2019
Comments: