Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
f-strings solution in Clear category for Dialogues by David_Jones
VOWELS = "aeiouAEIOU"
class Chat:
def __init__(self):
self.human_dialogue = []
self.robot_dialogue = []
def connect_human(self, human):
human.chat = self
def connect_robot(self, robot):
robot.chat = self
def show_human_dialogue(self):
return '\n'.join(self.human_dialogue)
def show_robot_dialogue(self):
return '\n'.join(self.robot_dialogue)
class Human:
def __init__(self, name):
self.name = name
def send(self, message):
self.chat.human_dialogue.append(f'{self.name} said: {message}')
message = ''.join('10'[ch in VOWELS] for ch in message)
self.chat.robot_dialogue.append(f'{self.name} said: {message}')
class Robot:
def __init__(self, serial_number):
self.serial_number = serial_number
def send(self, message):
self.chat.human_dialogue.append(f'{self.serial_number} said: {message}')
message = ''.join('10'[ch in VOWELS] for ch in message)
self.chat.robot_dialogue.append(f'{self.serial_number} said: {message}')
May 15, 2019