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.
In this problem, you will be writing a simple version of a question/answer artificial intelligence. Commonly used question/answer AIs (QAAIs) include Apple’s Siri, Google Home, Amazon’s Alexa, and others. If you’ve seen The LEGO Batman Movie, you’ll know that batman has a computer AI in his batcave that he calls ‘Puter. Because I love batman, and this movie is generally awesome, we will also call the AI implemented in this assignment “puter.”
Unlike the real-life QAAIs listed earlier, 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-1.py
on the command line.
When you run this you’ll see:
$ python3 puter-1.py
PUTER: Hello and welcome! Ask me no more than 10 questions.
PUTER: Go ahead, ask me something:
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:
.
Lines that the user types/inputs do not start with any prefix.
Puter will only know how to answer a few basic types of questions. Below, I describe each question that puter should process.
When you type how are you?
or how goes it?
(note: lower-case), puter will give you a simple reply.
For example:
...
PUTER: Go ahead, ask me something:
how are you?
PUTER: I am a computer program, so obviously I am excellent!
PUTER: Go ahead, ask me something:
how goes it?
PUTER: I am a computer program, so obviously I am excellent!
PUTER: Go ahead, ask me something:
Notice that puter replies the same way, regardless which of the two questions is asked.
When you type what is your birthday?
(again, lower-case), puter will reply as follows:
PUTER: Go ahead, ask me something:
what is your birthday?
PUTER: I am a computer program! I don't have a birthday :-(
PUTER: Go ahead, ask me something:
When you type what is your favorite color?
, puter will give you one of several answers.
The first time the question is asked in a puter session, puter will say red
.
The second time the question is asked, puter will answer blue
.
The third time the question is asked, it will answer green
.
The fourth time, it will start again from answering red
, and the pattern will continue.
Below is an example run of puter that demonstrates this pattern:
$ python3.X puter-1.py
PUTER: Hello and welcome! Ask me no more than 10 questions.
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: red!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: blue!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: green!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: red!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: blue!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: green!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: red!
PUTER: Go ahead, ask me something:
...
When you type what time is it?
or what is the date?
(note: lower-case), puter will tell you the current date/time.
For example:
...
PUTER: Go ahead, ask me something:
what time is it?
PUTER: The current date/time is 2017-02-13 08:42:19.728379
PUTER: Go ahead, ask me something:
...
PUTER: Go ahead, ask me something:
what is the date?
PUTER: The current date/time is 2017-02-13 08:42:19.728379
PUTER: Go ahead, ask me something:
The result provided by puter should be the actual current date and time.
This value is easy to fetch with built-in python functionality.
At the top of your file, you must import the datetime
module via:
from datetime import datetime
Once imported, you can fetch the current time by calling the now
function in the datetime
module (datetime.now()
).
Note that you will probably need to convert the “time” returned by the now()
function to a string, but you should know how to do that :-)
If the user types in any question/text other than the ones specifically described in this spec, puter will notify the user that it does not know how to process it.
When it encounters such a sentence, puter will say: Sorry, I can't understand you!
.
For example:
$ python3.X puter-1.py
PUTER: Hello and welcome! Ask me no more than 10 questions.
PUTER: Go ahead, ask me something:
why so serious?
PUTER: Sorry, I can't understand you!
PUTER: Go ahead, ask me something:
can I have some candy?
PUTER: Sorry, I can't understand you!
PUTER: Go ahead, ask me something:
why are you so dumb?
PUTER: Sorry, I can't understand you!
PUTER: Go ahead, ask me something:
Notice that the first line puter prints when run is:
PUTER: Hello and welcome! Ask me no more than 10 questions.
Puter should be implemented so that it can handle no more than 10 questions per session. Once 10 questions have been asked (both valid and invalid), puter will notify the user that the limit has been reached, and then exit. For example:
$ python 3.X puter-1.py
PUTER: Hello and welcome! Ask me no more than 10 questions.
PUTER: Go ahead, ask me something:
what time is it?
PUTER: The current time is 2017-02-13 09:28:55.076236
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: red!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: blue!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: green!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: red!
PUTER: Go ahead, ask me something:
how are you?
PUTER: I am a computer program, so obviously I am excellent!
PUTER: Go ahead, ask me something:
how are you?
PUTER: I am a computer program, so obviously I am excellent!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: blue!
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: green!
PUTER: Go ahead, ask me something:
blah blah blah blah blah blah blah blah blah blah blah
PUTER: Sorry, I can't understand you!
PUTER: Question limit reached. Bye!
After printing out PUTER: Question limit reached. Bye!
, puter should quit.
You can exit a python program by calling the exit()
function in the sys
module.
You will need to import the sys module at the top of your python script in order to use it (import sys
).
A user of puter may want to exit before typing in all 10 questions.
If a user types exit
as their question, puter will print PUTER: Bye!
and then exit.
For example:
python3.X puter-1.py
PUTER: Hello and welcome! Ask me no more than 10 questions.
PUTER: Go ahead, ask me something:
what time is it?
PUTER: The current time is 2017-02-13 09:32:50.554820
PUTER: Go ahead, ask me something:
what is your favorite color?
PUTER: red!
PUTER: Go ahead, ask me something:
how is your day going?
PUTER: Sorry, I can't understand you!
PUTER: Go ahead, ask me something:
exit
PUTER: Bye!
You can use the same sys.exit()
function to exit at this point as well.
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, February 17, 2017. It is due Friday, February 24, 2017, at 6:00pm.
Turn-in instructions:
.py
file in a directory named netid-assignment-5
where netid
is your netid. Make sure only the .py
file(s) exist in this directory, no others.netid-assignment-5
directory. The result should be named netid-assignment-5.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-5.zip
to the assignment-5 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!