Compsci 101, Fall 2016, Lab 5

MIX IT UP

For this lab you must work with a partner that you have not previously submitted a lab with.

The lab

In this lab you will:

You will need to snarf files for this lab. Those files are also here

Getting Credit for Lab 5

To get credit for lab, you will need to do the following by Sunday night:


Part 1: Files

Look at the file Information.py and the datafile athletes.txt (you can snarf the lab or see them here. )

Each line in the datafile has five parts of information about a person, with each part separated by a colon. Those five parts are first name, last name, gender (women or men), sport, and their height in inches (an integer).

Here is the data file:

Sean:Davis:men:soccer:72
Lexie:Brown:women:basketball:69
Jessica:Ho:women:tennis:65
Gurbani:Singh:women:golf:66
Harry:Giles:men:basketball:82
Nicolas:Alvarez:men:tennis:73
Quinn:Cook:men:basketball:74
Alyssa:Smith:women:tennis:65
DeVon:Edwards:men:football:69
Adam:Wood:men:golf:71
Elizabeth:Williams:women:basketball:75
Cameron:Moseley:men:soccer:76
Celine:Boutier:women:golf:64
Amile:Jefferson:men:basketball:81
Ashton:Miller:women:soccer:67
Daniel:Jones:men:football:77
Chalena:Scholl:women:tennis:67
Josh:Levine:men:tennis:71
Casey:Martinez:women:soccer:65
Lisa:Maguire:women:golf:66
Grayson:Allen:men:basketball:77
Rebecca:Greenwall:women:basketball:73
Alexander:Matlari:men:golf:72
Kyra:Lambert:women:basketball:69
Jahlil:Okafor:men:basketball:83
Kendall:Cooper:women:basketball:76 
Corbin:McCarthy:men:football:70
Luke:Kennard:men:basketball:77
Sandy:Choi:women:golf:67
Matt:Slotnick:men:soccer:68
Emily:Schubert:women:basketball:76
Imani:Dorsey:women:soccer:67
Marshall:Plumlee:men:basketball:84
Lizzy:Raben:women:soccer:69
Rebecca:Smaller:women:tennis:53

You should modify the code and answer the following questions in the google form.

  1. Explain how Information.py knows how to find the datafile athletes.txt.
  2. What type does the function process return?
  3. Explain what the function process does.
  4. Modify one line of function process so that it returns a list of lists instead, where each inner list is five strings of the five pieces of information of an athlete (in the same order as the datafile).

    For example, the list returned from process that uses the above datafile would be:
    
      [  ['Sean', 'Davis', 'men', 'soccer', '72'],
        ['Lexie', 'Brown', 'women', 'basketball', '69'],
       ['Jessica', 'Ho', 'women', 'tennis', '65'],
        
         ... REST NOT SHOWN
    
          ]
    
    
    
    We will call each list in this list, a list of athlete information.

    What is the new line of code?

  5. Write the function averageHeight that has one parameter, a list of lists of athlete information, and returns the average height (as a decimal number) of all the people in the list.

    What is the average height of all the people in the file? (call the function to answer this question)
  6. Cut and paste your averageHeight function here.
  7. Write the function heightRange that has three parameters: a list of lists of athlete information, and two integers named height1 and height2, where height1 is less than or equal to height2. This function returns a list of lists of athlete information for which their height is between height1 and height2 or equal to height1 or height2.

    Call this function to answer the question how many athletes are 6 ft or 6 ft 6 inches or between the two, and how many are there? What one line of code (that includes a call to this function) could print this answer?

  8. Cut and paste your heightRange function here.
  9. What one line of code would answer the question how many athletes are exactly 6 ft 2 inches? (this line should include a call to heightRange) How many are there?
  10. Write the function group that has three parameters: a list of lists of athlete information, and two strings named gender (value could be "men" or "women") and sport (Example, could be "soccer"). This function returns a list of lists of athlete information from the given list that matches the gender (either men or women) and the sport. For example if this function is called with gender equal to "women" and sport equal to "basketball", then it should return a list of lists of athlete information for only women basketball players.

    Cut and paste your group function here.

  11. Do not write another function but instead use the functions you have already written. What one line of code would answer the question of how many women tennis players there are, and what is that answer?
  12. Do not write another function but instead use the functions you have already written. What lines of code would print the average height of all women tennis players?
  13. Do not write another function but instead use the functions you have already written. What lines of code would print the average height of all basketball players (women and men)?
  14. What is another question you could ask about the datafile?

Part 2: Going over exam questions

(optional)

Work on problems from CompSci 101 Fall 2014 Sec1 exam. Work problems on paper in reverse order, doing problem 5 first, then 4, etc.