Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Python Please use the file function (simple) and slit method. Simple code to

ID: 3726440 • Letter: U

Question

Use Python

Please use the file function (simple) and slit method.

Simple code to understand and have very clearly Named Variables

Source Code

(Different than previously asked questions) DON'T use "def" or dictionary!

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:

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 separate 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.

EXAMPLE SIMILIAR CODE/ SIMPLICITY:

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 >>round (1.172142903,3) 1.172

Explanation / Answer

f = open('medalData.csv')#opening file, data = f.readlines()#reading data from the file,this data is in form of list, where each element is each line of data data = data[1:]#choosing all of dta and leaving the first line results_list = [] # this list stores lists of data for individual country # in the format [name,ratio,result] for line in data: # for every country rank,country,gold,silver,bronze,population = line.split(',') # the data split into list Medals = int(gold) + int(silver) + int(bronze) # total medals won by that country ratio = round(Medals * 10000000 / int(population), 3)#ratio calculated if ratio < .672: result= 'WELL Below Average' elif ratio
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote