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

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:

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 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:

# Create our input and output files fin = open("athletes_data.csv","r") fout = open("athlete_bmi.csv","w") # Write a header to the output file fout.write("Last,First,BMI ") # Read the header from the input file (it contains no usable data) header = fin.readline() # For each line (athlete) in the input file: split up the information into # usable chunks, compute the bmi, and write the information to the otuput # spreadsheet file in CSV format for athlete in fin: last,first,height,weight,country,gender,sport=athlete.split(",") weightKG = float(weight) heightMeters = float(height)/100 bmi = weightKG/(heightMeters)**2 fout.write(last+","+first+","+str(bmi)+" ") # Close each spreadsheet fin.close() fout.close() 
>>round (1.172142903,3) 1.172

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!