CompSciHW2

Homework 2 -- types, functions, and substitution Due Monday, Feb. 8

Use the following code as reference for problem 1:

a. A list of all positive integers smaller than n ex: [0, 1, 2, 3, 4] [0, 1]        [0, 1, 2, 3, 4, 5, 6, 7] b. The following sentence template: "The quick brown dog jumped over 5 foxes." "The terrible brown dog attacked 0 foxes." "The leaning brown dog replaced 99 foxes." "The absent brown dog confused 4 foxes." c. The following very similar lists: [8, 7, 4, 2, 2, 4, 7, 8]    [8, 7, 9, 0, 0, 9, 7, 8]     [8, 7, 6, 5, 5, 6, 7, 8]     [8, 7, 2, 3, 3, 2, 7, 8]     [8, 7, 6, 1, 1, 6, 7, 8] d. The outputs (total work and finished flag) of the following flow-chart: (> 4 days left) ---> (procrastinate) ^                            /     (work >= 10)  ---> (work is done) (<= 4 days left) ---> (add "5 - (#days left)" to work)
 * 1) In this code, name the type of each of the following:
 * u
 * 1) * gen_sph_surfpt
 * 2) * polar2cart
 * 3) ** Make sure you use one of the following types:
 * 4) ** basic type: int / float / string /
 * 5) ** derived type: [a], (a, b, c, ...) / a -> ... -> b -> c
 * 6) Write code that computes each of the following patterns, but replaces the variable part with 'x' (and 'y', 'z', etc.).
 * 7) * Be sure to write this as a function with "def f(x, y, etc.):" and use "return" to return the pattern as output.
 * 8) * Also, write the type of the function you have produced.

Your function should produce the following output for these (left,work) inputs :

input      output 6, 0 -> 0, False 5, 0 -> 0, False 4, 0 -> 1, False 3, 1 -> 3, False 2, 3 -> 7, False 1, 6 -> 10, True

3. Write for-loop to do each of the following tasks:

a. Build a list of 4 lines input by the user. Hint: use raw_input

b. Count the number of times the letter "e" appears in a string named 'x'.

c. Return the rot13 cipher of a lowercase string, "x.lower"

abc becomes nop while and ketchup becomes naq xrgpuhc
 * Explanation: rot13 changes each letter to the letter that appears 13 characters later alphabetically, for example
 * Hint: use (ord, chr, and the mod function), dont forget to subtract ord('a')