Assignment 1: Basics of Python and String Manipulation |
CSE 415: Introduction to Artificial Intelligence The University of Washington, Seattle, Autumn 2017 |
The reading for this assignment is
Python as a Second Language.
|
Due Friday, October 6, through
Catalyst CollectIt
at 23:59 PM.
You should turn in four files: (1) a file named a1.py of function definitions, (2) a file a1examplesplus.txt of example calls, results and answers to questions, (3) a file containing the Python code for your conversational agent, and (4) a text file containing a sample dialog between your agent and your partner's agent. For the file of examples, you can use a combination of input and output together with comment lines (beginning with a pound sign) to show that you have verified each of your answers on the computer. For each function, show a demonstration on the same example shown on this page, and two additional examples: one shorter (or smaller), and one longer (or larger) and more interesting (use your imagination). |
Part A. Defining Functions (30 points).
Write Python function definitions for the following requirements (worth 5 points each, except for numbers 2 and 4, which are worth 10 points each). You should be able to infer what each function should do by a combination of reading its name and examining the relationship between its input and ouput on the given examples. Note that the functions that accept lists as arguments must be able to handle lists of any length. For this assignment your functions do not have to validate the types of their inputs. That is, you may assume that they will be called with arguments of the proper types. In problem 2, you may find it helpful to write a helping function that can translate one character, and you may find the various string methods to be useful: islower(), isupper(), isdigit(), isalpha(), index(), and join(). You might also consider using the functions map(), and list(). The built-in Python functions ord and chr could come in handy. The mod operator ('%') may also be helpful. 1. three_x_cubed_plus_7(2) -> 31 2. mystery_code("abc Iz th1s Secure? n0, no, 9!") -> "TUV bS MA1L lXVNKX? G0, GH, 9!" (Hint: If a character of the input is alphabetic, then it undergoes a change of case as well as a mapping to a different place in the alphabet.) 3. pair_off([2, 5, 1.5, 100, 3, 8, 7, 1, 1, 0, -2]) -> [[2, 5], [1.5, 100], [3, 8], [7, 1], [1, 0], [-2]] 4. past_tense(['program', 'debug', 'execute', 'crash', 'repeat', 'eat']) -> ['programmed', 'debugged', 'executed', 'crashed', 'repeated', 'ate']Use the following rules for forming the past tense of a regular verb in English: (a) If the verb ends in 'e', add 'd'. (Example: 'execute' becomes 'executed'.) (b) If the verb ends with a 'y' immediately preceded by a consonant, change the 'y' to 'i' and add 'ed'. (Example: 'try' becomes 'tried'.) (c) If the word ends in one vowel (not two vowels) followed by one consonant (but not 'y' or 'w'), then repeat the consonant and add 'ed'. (Example: 'debug' becomes 'debugged'. (d) For the irregular verbs to have, to be, to eat, and to go, handle these as special cases. (e) In all other cases, add 'ed'. (Example: 'repeat' becomes 'repeated'.) You don't have to handle irregular verbs other than those mentioned in (d). |
Part B. Conversational Agents (70 points).
Create a Python program that simulates a human character in a dialog. Your program should have some definable personality, such as a widget salesman, entertainment star, political figure, etc. Besides being able to carry on a conversation with a human user, it should be able to join into conversations with the agents created by any member of the class. To do this, it will need to implement certain functions with a strict protocol. Your solution should follow these guidelines:
|
Updates and Corrections
During office hour on Oct. 3, the following questions came up, and answers are being provided here for everybody. (1) In Part B, how can the conversational agent program be used either in human-to-agent mode or agent-to-agent mode? The answer is to have the following code at the end of your file (substituting the name of your agent-startup method for "RunMyAgent"): if __name__ == "__main__": RunMyAgent()This will cause the program to operate in human-to-agent mode when it is being run independently, but when the file is imported, it will not run that way; then it will simply be there so that its respond can be called by the dialog.py
program.
(2) Should both partners turn in the same file sampleConversation.txt ?
The answer is NO. Although both partners may use the same conversation output, the comments
in the file should be different, since they should be pointing out the features of different
agents. Your file should comment on the features of YOUR agent during the conversation,
not the features of your partner's agent.
(3) How can we find partners for Part B? In class on Wednesday, we'll allocate a few minutes to the partnering issue, and least to identifying possible partners if not finding partners for everybody. Any additional updates or corrections will be made as needed to this page and mentioned here. |
Feedback Survey
After submitting your solution, please answer this survey |