Question: In Python, please! Restructure this program according to the model/view pattern so that these areas of responsibility are assigned to separate sets of classes. The

In Python, please! Restructure this program according to the model/view pattern so that these areas of responsibility are assigned to separate sets of classes.

The program should include a Doctor class with an interface that allows one to obtain a greeting, a signoff message, and a reply to a patients string.

To implement the greeting, define a method named greeting for the Doctor class. To implement the signoff message, define a method named farewell for the Doctor class. Both greeting and farewell should return a string with a greeting or farewell message respectively. The reply function is defined for you, it should be added as a method for the Doctor class.

The rest of the program, in a separate main program module, handles the users interactions with the Doctor object. Develop this program with a terminal-based user interface.

doctor.py code:

""" File: doctor.py Starter 9.5 Conducts an interactive session of nondirective psychotherapy. Adds a history list of earlier patient sentences, which can be chosen for replies to shift the conversation to an earlier topic. """

import random

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"}

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

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

def main(): """Handles the interaction between patient and doctor.""" print("Good morning, I hope you are well today.") print("What can I do for you?") while True: sentence = input(" >> ") if sentence.upper() == "QUIT": print("Have a nice day!") break print(reply(sentence))

# The entry point for program execution if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!