Question: Use Python Please use the file function (simple) Simple code to understand and have very clearly Named Variables: beginners level:) Source Code We will look
Use Python
Please use the file function (simple)
Simple code to understand and have very clearly Named Variables: beginners level:)
Source Code
We will look at the idea of how many olympic medals were won by a country compared to it's population. The 2018 population of the medal-earning countries that participated in the PyeongChang 2018 Winter Olymipics was 2,460,774,720 people (excluding Russia). Further, 290 medals were won (again, excluding Russia). This means that there were:
290 / 2,460,774,720 * 10,000,000 =1.178 medals awarded for every 10,000,000 people
For each country, we can use it's population and it's medal count to calculate whether it was above average, below average, WELL above average, or WELL below average based on:
| Ratio | Result |
| Less than 0.672 | WELL Below Average |
| 0.672 - 1.177 | Below Average |
| 1.178 | Average |
| 1.179-1.672 | Above Average |
| Greater than 1.672 | WELL Above Average |
The Assignment
Download the following data from the 2018 Winter Olympics in PyeongChang:
medalData.csv
This is a text file (although it is likely that your operating system will recognize it as openable by Excel and give it an Excel icon). Open this file with either Excel or a basic text editor. Notice that this file consists of a header line and then a sequence of data consisting of comma-separated fields of country name, medal count, and a population.
Write a program (called pa06.py) that:
opens this file for reading
reads and throws away the first line since it is the header line
for each country line:
splits it into six components (remember how to use the split method of a string)
adds the gold, silver, and bronze medal counts to get a total medal count
uses population and medal count to calculate it's average per 10 million people
prints to the screen a message with country, ratio, and an indication of whether this is above or below average
Once you get that working, modify the program to write to a file called results.csv rather than print to the screen. The results.csv file should be formatted similarly to the medalData.csv file.
HINT: Use the round function to round your computations to 3 decimal places. For example:
Finally, after you have finished writing to the results.txt file, print to the screen (not to the text file) the country with the highest and lowest ratios.
>>round (1.172142903,3) 1.172Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
