Assignment 1: Functioning with Python |
CSE 415: Introduction to Artificial Intelligence The University of Washington, Seattle, Winter 2009 |
The reading for this assignment is
Chapters 1-4
in Introduction to Python for
Artificial Intelligence.
|
Due Friday, January 16 through
Catalyst Collect-It
at 12:00 noon.
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, provide the definition*, a demonstration on the same example shown on this page,
and three additional examples: one shorter (or smaller),
one longer (or larger) and one more interesting
case (use your imagination).
[Clarification posted Jan. 11:]
You should turn in two files: (1) a file (with extension .py) of function definitions, and (2) a file of example calls and results.
|
Defining Functions (25 points).
Write Python function definitions for
the following requirements (worth 5 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.
1. five_x_plus_7(3) -> 22 2. sub_cipher("abc Iz this Secure?", 2) -> "def Lc wklv Vhfxuh?" 3. sum_triples([2, 5, 1.5, 100, 3, 8, 7]) -> [8.5, 111, 7] 4. times_i([7, 13, 3, 2.2, 5, 100]) -> [0, 13, 6, 6.6, 20, 500] (Don't worry about number formatting.) 5. double_con_cat([1, "ha", 7, "yeah! ", 13.5]) -> [2, "haha', 14, "yeah! yeah! ", 27.0]For each function, include the following in your turned-in document: (a) the Python definition of the function, (b) a cut-and-pasted transcript of your function being applied to the example argument shown above, (c) a cut-and-pasted transcript of your function being applied to the new examples that you make up (see above); |
Optional for 5 points extra credit.
Write a Python program that makes up new poems in the
Haiku form. The Haiku form is as follows: each poem consists
of three lines. The first line has 5 syllables. The second
line has 7 syllables, and the third line has 5 syllables.
Rhyming is not usual in this form. Here's an example:
Artificial smarts Wires, chips, disks, and batteries Seems it's just hardwareYour program should use random choices from lists of words to make up its poems. Try to have the program's poems incorporate one or more themes of your choice. If you can, try to have the third line of each poem seem ironic or clever. Show five different Haiku produced by your program. |
Optional for 5 points extra credit.
Write a definition for a Python function permutations
that returns a list of all permutations of its
argument, which is a list.
permutations([0, 1, 2]) -> [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]Test your permutation function on range(4) and on ['red', 'green', 'blue'] as well as three more examples following the same guidelines as for the extra example in the first set of functions above. |
(corrected Jan. 8 for consistency in the number of examples to provide for each function. Modified Jan. 11 as per Emily's request for a Python file of function definitions to be turned in along with the file of examples.) |