Assignment 1: Functioning with Python |
CSE 415: Introduction to Artificial Intelligence The University of Washington, Seattle, Winter 2007 |
The reading for this assignment is
Chapters 1-4
in Introduction to Python for
Artificial Intelligence.
|
Due Friday, January 12 through
Catalyst E-Submit
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 3 additional examples: one shorter (or smaller),
one longer (or larger) and one more interesting
case (use your imagination).
Write Python function definitions for the following requirements (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. 1. two_x_plus_1(5) -> 11 2. sub_cipher("abc Iz this Secure?", 2) -> "cde Kb vjku Ugewtg?" 3. pair_off_and_multiply([2, 5, 1.5, 100, 3, 8, 7]) -> [10, 150.0, 24, 49] 4. times_i([7, 13, 3, 2.2, 5, 100]) -> [0, 13, 6, 6.6, 20, 500] 5. double_con_cat([1, "ha", 7, "yeah! ", 13.5]) -> [2, "haha', 14, "yeah! yeah! ", 27.0] |
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 ['alpha', 'beta', 'gamma'] as well as three more examples as per the instructions above. |