This assignment is primarily python. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors!
When grading your assignments, each problem/script/function will be thoroughly tested with many types of input, so make sure you test your scripts/functions well!
The python in this assignment will be graded using python 3.6, and tests will be run on a Mac machine. In general python works well cross-platform, but if you want to be absolutely sure your program works as expected, test on a mac! Any python version 3.4 or newer should suffice though.
All of your scripts should be well-formatted and easy for the graders to read. Each script should have a header comment at the top that has the following format:
#
# Author: Student Name
# Description:
# A short description of what this program / script / set of functions does!
#
Each function in your script(s) should have a descriptive comment above it. If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.
This problem is new version of assignment 5, where we implemented a very simple version of the puter AI. In this assignment we will re-implement puter, but it will have some more interesting and advanced features.
Similar to the previous puter, we are not going to interact with puter
with our voices.
Puter will accept questions and inquiries from standard input on the command-line, and print out it’s answers to the command line as well.
To start up puter, you will run python3.X puter-2.py
on the command line.
When you run this you’ll see:
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
From this point, the user (you) can type a question, and then hit “Enter” to have puter process the question and provide an answer.
As you read through the rest of the problem specification, notice that all lines that puter outputs are started with PUTER:
(or a different name, perhaps?).
Lines that the user types/inputs do not start with any prefix.
For this version of puter, there is no longer a 10-question limit.
The exit
keyword should work similarly to the last assignment.
You will have to make a change to save information to a file though.
More on that later.
This version of puter should handle the how are you?
, how goes it?
, what time is it?
and what is the date?
questions in the same way that the first version of puter did.
You should not support what is your favorite color?
and what is your birthday?
.
When this version of puter encounters a question or statement that it does not support, it should respond in a similar way that the previous version did. The response should be:
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
why so serious?
PUTER: Huh?
can I have some candy?
PUTER: Huh?
why are you so dumb?
PUTER: Huh?
...
This version of puter will have the ability to “remember” various bits of personal information that you tell it.
Thus, this version of puter will both respond to questions (ending in ?
) and reason about statements (ending with no specific punctuation).
Puter will accept statements of the form my favorite A is B
, where A
is a string and B
is also a string.
Puter will remember that B
is your favorite A
.
Later, if you ask what is my favorite A?
, puter will respond with B
.
Below are a few examples:
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
I do not know how to speak Chinese
PUTER: Huh?
my favorite food is orange chicken
PUTER: OK, got it.
my favorite car is a 72 corvette
PUTER: OK, got it.
what is my favorite food?
PUTER: Your favorite food is orange chicken.
what is my favorite car?
PUTER: Your favorite car is a 72 corvette.
what is the best food?
PUTER: Huh?
...
Notice the pattern: Statements that include new personal information for puter to remember start with my favorite
, and should always contain ` is .
Everything between
my favorite ` and ` is ` is what the user can later ask about.
Everything between ` is ` and the end of the string is the “answer”.
If the user asks for a “favorite” that has not yet been specified, puter should reply with Not sure :-(
.
Personal information specified in a puter session should be saved to a file, and remembered for the next session.
All of the info should be saved to a file named favorites.txt
in the same directory as puter-2.py
.
When a session is closed with exit
, puter will save all favoties.
A good technique for saving info like this to a file is given in the lecture notes on file io.
Below is an example demonstrating this feature:
$ cat favorites.txt
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
what is my favorite drink?
PUTER: Not sure :-(
my favorite drink is coffee
PUTER: OK, got it.
what is my favorite drink?
PUTER: Your favorite drink is coffee.
exit
PUTER: Personal info saved!
PUTER: Bye!
$
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
what is my favorite drink?
PUTER: Your favorite drink is coffee.
exit
PUTER: Personal info saved!
PUTER: Bye!
$
When a new puter session is started, it should load all information from favorites.txt
.
PUTER
is the default name for this AI.
However, in this version, we will be able to change puter’s name within a single session.
To do this, issue the statement:
rename yourself to X.
Notice that the command starts with rename yourself to
.
The name itself what lies between these two strings.
The AI’s name is a case-sensitive value.
PUTER
Puter
and puter
are treated as three distinct names.
Here are a few interactive examples of changing the name:
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
rename yourself to Batman
Batman: OK, name changed!
hi batman
Batman: Huh?
rename yourself to Dwight Schrute
Dwight Schrute: OK, name changed!
how are you dwight?
Dwight Schrute: Huh?
...
The name does not need to be saved from session-to-session.
Notice that puter no longer says PUTER: Go ahead, ask me something:
in between each statement.
This applies for all questions/statements/features in this assignment.
Below are a few example sessions (or in some cases, sequences of sessions). Your program should behave identically to these scenarios:
$ cat favorites.txt
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
my favorite car is a 72 corvette
PUTER: OK, got it.
what is my favorite car?
PUTER: Your favorite car is a 72 corvette.
my favorite car is a ford f-250
PUTER: OK, got it.
what is my favorite car?
PUTER: Your favorite car is a ford f-250.
exit
PUTER: Personal info saved!
PUTER: Bye!
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
what is my favorite car?
PUTER: Your favorite car is a ford f-250.
exit
PUTER: Personal info saved!
PUTER: Bye!
$
$ cat favorites.txt
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
rename yourself to SuperMan
SuperMan: OK, name changed!
my favorite food is orange chicken
SuperMan: OK, got it.
what time is it?
SuperMan: The current date/time is 2017-03-03 09:55:42.260020
ename yourself to PUUUUTER
SuperMan: Huh?
what is my favorite food?
SuperMan: Your favorite food is orange chicken.
what is my favorite drink?
SuperMan: Not sure :-(
exit
SuperMan: Personal info saved!
SuperMan: Bye!
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
what is my favorite food?
PUTER: Your favorite food is orange chicken.
exit
PUTER: Personal info saved!
PUTER: Bye!
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
rename yourself to Sherlock
Sherlock: OK, name changed!
my favorite movie genre is mystery
Sherlock: OK, got it.
what is my favorite movie genre?
Sherlock: Your favorite movie genre is mystery.
my favorite tv show is sherlock
Sherlock: OK, got it.
what is my favorite movie genre?
Sherlock: Your favorite movie genre is mystery.
what is my favorite tv show?
Sherlock: Your favorite tv show is sherlock.
exit
Sherlock: Personal info saved!
Sherlock: Bye!
$
$ cat favorites.txt
food | orange chicken
drink | coffee
city | tucson
$
$ python3 puter-2.py
PUTER: Hello and welcome! Let's talk...
what is my favorite city?
PUTER: Your favorite city is tucson.
what is my favorite drink?
PUTER: Your favorite drink is coffee.
what is my favorite food?
PUTER: Your favorite food is orange chicken.
what is my favorite ice cream?
PUTER: Not sure :-(
exit
PUTER: Personal info saved!
PUTER: Bye!
$
This assignment requires printing out precise text messages and notifications. As already mentioned, it is important to be precise when doing these printouts.
We will only take minimal points off for very minor differences (for example, minor character spacing issues). However, we will take points off for any non-trivial differences, so try to be as precise as you can!
This problem will be graded out of 100 points.
This was assigned on Friday, March 3, 2017. It is due Friday, March 10, 2017, at 6:00pm (right before spring break).
Turn-in instructions:
.py
file in a directory named netid-assignment-7
where netid
is your netid. Make sure only the .py
file(s) exist in this directory, no others.netid-assignment-7
directory. The result should be named netid-assignment-7.zip
.
There are instructions online for how to do this with a Mac and how to do this with a PC.
Make sure to zip the directory, not the file(s) individually!netid-assignment-7.zip
to the assignment-7 D2L dropbox.Following these turn-in instructions closely is very important, because our grading scripts will depend on some of the details. You may lose points if these instructions are not followed precisely!