Compsci 101, Fall 2017, 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: Working on the Seven Steps

Part 1 is an exercise in class you will work in a group of 3-4 people and then turn in.

You will be given legos of two different colors and a particular Lego pattern that grows with one additional lego each time. (Your lego pattern has two different colors also, but they may be different colors, just assume they are the same color as the legos in the pattern. ) You want to think about how the pattern grows each time you add another lego and how to give a general description of how the pattern is growing.

Follow the following steps.

  1. You are shown the pattern for a sequence of legos. With the legos and the board, build what the pattern would look like if there was one more lego added.
  2. On paper, Write the pattern number you are building and write a general algorithm to describe how to place legos in the pattern for N legos. Write all your names on the paper.
  3. Give your algorithm to your UTA and they will give you another groups algorithm (for a different pattern). Follow their algorithm exactly and see if you can build their pattern for 8 legos. Check with the group to see if you built the pattern they had.
  4. Answer the following questions about what you just did in the google form.
    1. Was the other team able to build your pattern for 8 legos correctly? If not, what did you forget to tell them?
    2. Do you think the other team would have been able to build the pattern for 9 legos correctly following your algorithm?
    3. Any comments on the difficulty or not of writing a general algorithm to explain the pattern for N legos.

Part 2: 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
Brittain:Brown:men:football:73
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
Shaun:Wilson:men:football:69
Rebecca:Greenwall:women:basketball:73
Alexander:Matlari:men:golf:72
Kyra:Lambert:women:basketball:69
Austin:Parker:men:football:73
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
Ben:Humphreys:men:football:74
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?