CS 170 Lab 10: Files and Dictionaries

This is a lab exercise that involves writing a function that works with files and dictionaries. It should be helpful for understanding Program 3. I want you to work on this lab individually, not in pairs.

Write a function called scoreData that takes the name of a file as its input parameter. Each line of this file will contain a name (with no spaces) followed by a space, followed by a number. You should store this data in a dictionary where the key is the name and the value is a list of all the numbers associated with that name. When all the data is stored in the dictionary, you should calculate and print out a table with each name (in alphabetical order) on a line with the max, min and median values from the list associated with that name. You are welcome to cut and paste code from class for calculating the median.

For example, given an input file (available as lab10.txt) containing:

Jane 47
Joe 48
Bob 37
Bob 44
Jane 45
Jane 49
your program should print the output:
Name  Max Min Median
Bob   44  37  40.5
Jane  49  45  47
Joe   48  48  48

When you are convinced that your function is correct, well-documented and your name is in the file, you should upload your source code choosing Lab 10 as the assignment.