Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In PYTHON ASAP please! I need help integrating a Singleton pattern into the following code: import random class Doctor(object): author : name Doctor class

In PYTHON ASAP please! I need help integrating a Singleton pattern into the following code:

import random

class Doctor(object): """ author : name Doctor class """

# static attributes history = []

hedges = ("Please tell me more.", "Many of my patients tell me the same thing.", "Please coninue.")

qualifiers = ("Why do you say that ", "You seem to think that ", "Can you explain why ")

replacements = {"I": "you", "me": "you", "my": "your", "we": "you", "us": "you", "mine": "yours", "you": "I", "your": "my", "yours": "mine"} # empty constructor

def __init__(self): pass

# reply method given def reply(self, sentence): """Implements three different reply strategies.""" probability = random.randint(1, 5) if probability in (1, 2): # Just hedge answer = random.choice(Doctor.hedges) elif probability == 3 and len(Doctor.history) > 3: # Go back to an earlier topic answer = "Earlier you said that " + \ self.changePerson(random.choice(Doctor.history)) else: # Transform the current input answer = random.choice(Doctor.qualifiers) + \ self.changePerson(sentence) # Always add the current sentence to the history list Doctor.history.append(sentence) return answer

def changePerson(self, sentence): """ Replaces first person pronouns with second person pronouns. """ words = sentence.split() replyWords = [] for word in words: replyWords.append(Doctor.replacements.get(word, word)) return " ".join(replyWords)

# two functions added for greeting and # farewell message def greeting(self): return "Good morning, I hope you are well today"

def farewell(self): return "Have a nice day!"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions