Assignment 1: Basics of Python
CSE 415: Introduction to Artificial Intelligence
The University of Washington, Seattle, Autumn 2009
The reading for this assignment is Chapters 1-4 in Introduction to Python for Artificial Intelligence.
Due Thursday, October 8 (Changed from Wednesday, October 7), through Catalyst CollectIt at 11:00 AM. (The dropbox is available, as of Oct. 1 at 1:15.)

You should turn in two files: (1) a file (with extension .py) of function definitions, and (2) a file (with extension .txt) of example calls and results. 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).
 

Defining Functions (30 points). Write Python function definitions for the following requirements (worth 5 points each, except for number 5, which is worth 10 points). 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.
1. ten_x_plus_1(7) -> 71

2. substitution_cipher("abc Iz this Secure?", 6) -> "hij Pg aopz Zljbyl?"

3. diff_doubles([2, 5, 1.5, 100, 3, 8, 7])  ->  [-3, -98.5, -5, 7]

4. future_tense(['program', 'debug', 'execute', 'crash', 'repeat']) ->
 ['will program', 'will debug', 'will execute', 'will crash', 'will repeat']

5. past_tense(['program', 'debug', 'execute', 'crash', 'repeat']) ->
 ['programmed', 'debugged', 'executed', 'crashed', 'repeated']
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) In all other cases, add 'ed'. (Example: 'repeat' becomes 'repeated'.) You don't have to handle irregular verbs.
Generating Possibilities (10 points). Write a definition for a Python function combinations that takes two arguments, the first being a list, and the second being an integer, and that returns a list of all combinations of elements from the given list, taken k at a time, where k is the given integer.
combinations([0, 1, 2], 2) ->  [[0, 1], [0, 2], [1, 2]]
Test your combination function on (range(5), 2) and on (['red', 'green', 'blue', 'black'], 2) as well as two more examples of your choice.
Updates and Corrections If necessary, updates and corrections will be posted here and mentioned in class or on the mailing list. (Last edited on October 2, correcting the point allocations and numbering of exercises. Previously, corrected "programm" and announced that the dropbox is open. Access to the dropbox was also corrected on Oct. 2)