111 lab5b

Computer Science 111 – Fundamentals of Programming I Programming Project 5b
Due date: 11:59PM Friday, 19 October

Warmup

Run the following expressions or statements in the shell:

dir(dict)
help(dict.get)
data = {"height": 69, "weight": 160, "name": "Jim"}
data
len(data)
data["weight"]
data["hair-color"]
print(data.get("hair-color", None))
data.pop("weight")
data
list(data.keys())
list(data.values())

Copy the file doctor.py from the web page to your project5 folder (or create a new folder project5b). The program contained therein is a simplified version of a famous program called doctor that was developed at M.I.T. in the early 1960s by the M.I.T. computer scientist Joseph Weizenbaum. The doctor program engages in a conversation with the computer user, in which it mimics a nondirective style of psychotherapy. The doctor in this kind of therapy is essentially a good listener who responds to the patient’s statements by rephrasing them or indirectly asking for more information. Run this program to try out a session. After entering “quit,” run the program again by enteringmain() in the shell.

To Turn in

Launch idle3 and complete the following exercises.

  1. Add verbs to the replacements dictionary, so the doctor says (for example) you

    are instead of you am.

  2. Normalize the inputs so that the processing is not case-sensitive. Hint: all of the keys in the replacements dictionary should be in lowercase and each input word should be converted to lowercase before it is sent to the dictionary.
  3. Modify the program so that the doctor occasionally responds with a randomly chosen hedge, such as “Please tell me more.”
  4. When the patient addresses the doctor personally, the persons are not changed properly in the doctor’s reply. Test the program with “you are not a helpful therapist” to see this. Fix this problem by repairing the dictionary of replacements.
  5. In real life, conversations often shift focus to earlier topics. Modify the doctor program to support this capability. Add each patient input to a history list. Then, occasionally choose an element at random from this list, change persons, and prepend the qualifier “Earlier you said that ” to this reply. Be sure that the history list holds at least three entries before using it and that you add inputs to the history list after replies are generated.
  6. Extra Credit opportunities
    a) Do a version of the doctor program for another language. b) Have the doctor respond appropriately to swearing.
    c) Support contractions (I’m → you’re, etc.)

Your turnin this week should be your modified doctor.py program.