Graded Problem Set #3.4
File Problem
Background
These problems should be completed on your own. Unlike the practice problems, where you are allowed, and even encouraged, to talk about the process with your classmates, these should be attempted on your own. If you have difficulty with these, please reach out to me for assistance or guidance.
These problems will be completed using an editor such as Thonny or IDLE and submitted to Autolab for grading.
Introduction
We all love a good Olympic story. I mean, who didn't tear up when they watched the Jamaican bobsled team in Cool Runnings?
We all cheer for the good old U.S. of A. but we also like to cheer for the underdogs. But what exactly does it mean to be an underdog? Sure, a team that doesn't even really know about snow is an underdog. But other than that, a single medal won by a team from a tiny country just might be more impressive than 3 medals won by a much larger country.
In this activity you will look at the ratio of size of a country compared to the # of medals it won to try to figure out which countryreally performed better than we might expect.
Program Guide
For this assignment you should test with the following data sets:
- 2012_Olympic_Medals.csv [From the summer Olympics in London, England] The larger file
- 2014_Olympic_Medals.csv [From the winter Olympics in Sochi, Russia] This is the smaller file
- 2018_Olympic_Medals.csv [ From the winter Olympics in Korea]
Part 1 - Create a function called: totalPopulation()
This function should:
- Parameters:
- input file name - (you may use any of the files from above for testing)
- Actions:
- Opens the input file
- "Throws away" the header file
- Calculates the sum of the populations in the file
- Closes the file
- Returns:
- The total population of all of the countries who won medals at that Olympics
- Example Run
This function will be assessed by
Part 2 - Create a function called: totalMedals()
This function should:
- Parameters:
- input file name - (you may use any of the files above for testing)
- Actions:
- Opens the input file
- "Throws away" the header file
- Calculates the sum of ALL of the medals won in the file
- Closes the file
- Returns:
- The total medal count for all of the countries who won medals at that Olympics
- Example Run
This function will be assessed by
Part Three - Create a function called: medalRatios()
This function should:
- Take Two Parameters:
- input file name - (you may use either of the files above for testing)
- output file name
- Returns:
- Nothing
- Actions:
- Opens the input file
- Opens the output file
- Pulls off the header and adds one more column labeled "Medal Ratio"
- For each country provided in the data file you opened:
- extract population and total medals won just for that country
- calculate the medal ratio of medals to population per billion people as done above
- write the original data PLUS the country's medal ratio (rounded to 2 decimal places)
- Closes both files
- Example Run

- Note, you do not need to include the print statement I did in my example. But you may.
- Example Output
This function will be assessed by


