In Class: Week 8 Wednesday and Friday:
Nested Loops, File I/O


If you already copied over files from my week08 subdirectory, then copy over three new files in your week08 directory:

$ cd
$ cd cs21/class
$ cd week08

$ cp  ~newhall/public/cs21/week08/listoflists.py .
$ cp  ~newhall/public/cs21/week08/gradebook.txt .
$ cp  ~newhall/public/cs21/week08/gradebook.py .
Otherwise, create a week08 subdirectory in your cs21/class directory:
$ cd
$ cd cs21/class
$ mkdir week08
$ cd week08
Then copy over my week08 files:
$ cp ~newhall/public/cs21/week08/* .

After class, you can copy over code I wrote in class doing the following:

$ cp ~newhall/public/cs21/week08/tia* .

  1. Open stars.py and we will implement a function that takes a value, n, and draws two patterns of stars of size n. For example, if n is 5:
    *
    * *
    * * *
    * * * *
    * * * * *
    
            *
          * * *
        * * * * *
      * * * * * * *
    * * * * * * * * *
    
    One restriction is that we will not allow the use of the string repetion operator in this solution:
      # something like this is not allowed
    	print " *" * 5
    
    Instead the only two print statements that we can use are:
      print "*",  # this prints a single star string followed by a space 
      print " ",
    
  2. Next, we are going to write a program that reads in data from a file and stores it in a list of lists. This program implements processing a gradebook for a class. It starts by reading in gradebook entries from a file. Each entry is of the form:
      Name1  grade1  grade2  grade3  ... gradeN
      Name2  grade1  grade2  grade3  ...  gradeN
    
    We are going to write a function to read in each line into a list of values, the first element will be the name string, the subsequent ones will be the grades stored as int values:
      ["name string", grade1, grade2, ... grade N]
    
    and for each list is creates it will add it to the list of lists to produce a data structure that looks like the following:
                  -------
    gradebook---> | *---|-------> ["name1 string", grade1, grade2, ..., grade N]
                  |-----|
                  | *---|-------> ["name2 string", grade1, grade2, ..., grade N]
                  |-----|
                  | *---|-------> ["name3 string", grade1, grade2, ..., grade N]
                  |-----|
                     .
                     .
                     .
                  |-----|
                  | *---|-------> ["nameM string", grade1, grade2, ..., grade N]
                  -------
    
    
    Then we will write some functions for doing something with this list of lists.

    1. printStudentInfo(student, gradebook): prints out the information about one student given its student number.
    2. printNames(gradebook): prints out the names of all students in the gradbook
    3. printQuizScores(quiznum, gradebook): prints out the student scores for the given quiznumber
    4. printGradeBook(gradebook): prints out the entire grade book contents in tabular format
    5. getAveQuizGrade(quiz_n, gradebook): returns the average quiz grade for a specific quiz
    6. getAveGrade(student, gradebook): returns the average grade for a specific student