First Summer 2006


Lab Twelve: Methods
Consider this:

def f(x):
    return g(x) + (h(h(x))

def g(x): 
    return 4 * h(x)

def h(x): 
    return x * x + k(x) - 1

def k(x): 
    return 2 * (x + 1)

Given the definitions above:

  1. What does
    f(2)
    evaluate to?

  2. What does
    g(h(2))
    evaluate to?

  3. What does
    k(g(2) + h(2))
    evaluate to?

  4. What does
    f(0) + f(1) + f(2)
    evaluate to?

  5. What does
    f(-1) + g(-1) + h(-1) + k(-1)
    evaluate to?

Justify your answers.

The lab assignment for today is this:

  1. Write a method that calculates the sum of all elements in a list of numbers.
  2. Write a method that counts the number of even numbers in a list of numbers.
  3. Write a method that takes two arguments: and returns a list with all occurences of a removed.
  4. Write a method that sorts a list of numbers in ascending order.
  5. Write a method that takes a list of numbers and removes from all elements that appear for a second time (or more) in the list.

Do as much as you can, turn in what you have at the end of the lab.


Last updated: May 30, 2006 by Adrian German for A201/A597