In Class: Week 9, list algorithms

Create a week09 subdirectory in your cs21/class directory and copy over my starting point files:

    $ cd 
    $ cd cs21/class
    $ pwd

    $ mkdir week09        
    $ cd week09
    $ pwd

    $ cp ~newhall/public/cs21/week09/* .
After class, you can copy over my files by doing:
$ cp ~newhall/public/cs21/week09/tia* .

After taking a look at what does, we are going to add some code to
  1. First, we are going to add a function to find an element in a list of integer values.

  2. Next, we are going to think about a better way to implement this function.

  3. Also, are examples of using string formatting for print statements. The general form of formatted print statement looks like:
    print "format string with special place holders for values" %(argument list)
    For example:
    print "an int value: %d, a float: %f, a string: %s" %(23, 9.8, "hello")
    an int value: 23, a float: 9.800000, a string: hello
    The %d, %f, and %s in the format string are place holders for an int, a float, and a string value, and each gets replaced with its corresponding value from the argument list %(23, 9.8, "hello") in what print outputs.

    Using formatted string form of print statements is sometimes more convenient than having to list: string, value, string, value, ...:

    print "an int value", 23, "a float", 9.8, "a string", "hello"
    The real advantage of using formatted print statements is that you have much more control over print's output. For example, the formatted print statement:
    print "%10s \t %5d \t %5.2f" %(sval, ival, fval)
    prints out a string value in a field width of 10 characters wide, then a tab character, then an int value in a field of 5 characters wide, then a tab character, and then a float value in a field of 5 characters wide with a precision of 2 places beyond the decimal point.

    This is very useful is you want to line up tabular output and some of the numerical values that you are printing out have different numbers of characters, or if you want to print a differnt precision of floating point values than the default.

    Take a look at other examples in this file, and try running it to see what the formatted print statements do.