ID,Name,Sex,Age,Height,Weight,Team,NOC,Games,Year,Season,City,Sport,Event,Medal 1,Imen Zaabar,F,15,155,44,Tunisia,TUN,1996 Summer,1996,Summer,Atlanta,Gymnastics,Gymnastics Women's Uneven Bars,Gold...

Hi, I've attached the directions for this project and the code that I have begun for it. I have done about 1/3 of the project with the first 3 functions complete and passing the tests. I need help with the last functions. I have also attached a test file that is used for the assignment.


ID,Name,Sex,Age,Height,Weight,Team,NOC,Games,Year,Season,City,Sport,Event,Medal 1,Imen Zaabar,F,15,155,44,Tunisia,TUN,1996 Summer,1996,Summer,Atlanta,Gymnastics,Gymnastics Women's Uneven Bars,Gold 4,Edgar Lindenau Aabye,M,34,NA,NA,Denmark/Sweden,DEN,1900 Summer,1900,Summer,Paris,Tug-Of-War,Tug-Of-War Men's Tug-Of-War,Gold 15,Arvo Ossian Aaltonen,M,30,NA,NA,Finland,FIN,1920 Summer,1920,Summer,Antwerpen,Swimming,Swimming Men's 200 metres Breaststroke,Bronze 15,Arvo Ossian Aaltonen,M,30,NA,NA,Finland,FIN,1920 Summer,1920,Summer,Antwerpen,Swimming,Swimming Men's 400 metres Breaststroke,Bronze 16,Juhamatti Tapio Aaltonen,M,28,184,85,Finland,FIN,2014 Winter,2014,Winter,Sochi,Ice Hockey,Ice Hockey Men's Ice Hockey,Bronze 17,Paavo Johannes Aaltonen,M,28,175,64,Finland,FIN,1948 Summer,1948,Summer,London,Gymnastics,Gymnastics Men's Individual All-Around,Bronze 17,Paavo Johannes Aaltonen,M,28,175,64,Finland,FIN,1948 Summer,1948,Summer,London,Gymnastics,Gymnastics Men's Team All-Around,Gold 17,Paavo Johannes Aaltonen,M,28,175,64,Finland,FIN,1948 Summer,1948,Summer,London,Gymnastics,Gymnastics Men's Horse Vault,Gold 17,Paavo Johannes Aaltonen,M,28,175,64,Finland,FIN,1948 Summer,1948,Summer,London,Gymnastics,Gymnastics Men's Pommelled Horse,Gold 17,Paavo Johannes Aaltonen,M,32,175,64,Finland,FIN,1952 Summer,1952,Summer,Helsinki,Gymnastics,Gymnastics Men's Team All-Around,Bronze 20,Kjetil Andr Aamodt,M,20,176,85,Norway,NOR,1992 Winter,1992,Winter,Albertville,Alpine Skiing,Alpine Skiing Men's Super G,Gold 20,Kjetil Andr Aamodt,M,20,176,85,Norway,NOR,1992 Winter,1992,Winter,Albertville,Alpine Skiing,Alpine Skiing Men's Giant Slalom,Bronze 20,Kjetil Andr Aamodt,M,22,176,85,Norway,NOR,1994 Winter,1994,Winter,Lillehammer,Alpine Skiing,Alpine Skiing Men's Downhill,Silver 20,Kjetil Andr Aamodt,M,22,176,85,Norway,NOR,1994 Winter,1994,Winter,Lillehammer,Alpine Skiing,Alpine Skiing Men's Super G,Bronze 20,Kjetil Andr Aamodt,M,22,176,85,Norway,NOR,1994 Winter,1994,Winter,Lillehammer,Alpine Skiing,Alpine Skiing Men's Combined,Silver 20,Kjetil Andr Aamodt,M,30,176,85,Norway,NOR,2002 Winter,2002,Winter,Salt Lake City,Alpine Skiing,Alpine Skiing Men's Super G,Gold 20,Kjetil Andr Aamodt,M,30,176,85,Norway,NOR,2002 Winter,2002,Winter,Salt Lake City,Alpine Skiing,Alpine Skiing Men's Combined,Gold 20,Kjetil Andr Aamodt,M,34,176,85,Norway,NOR,2006 Winter,2006,Winter,Torino,Alpine Skiing,Alpine Skiing Men's Super G,Gold 21,Ragnhild Margrethe Aamodt,F,27,163,NA,Norway,NOR,2008 Summer,2008,Summer,Beijing,Handball,Handball Women's Handball,Gold 25,Alf Lied Aanning,M,24,NA,NA,Norway,NOR,1920 Summer,1920,Summer,Antwerpen,Gymnastics,Gymnastics Men's Team All-Around Free System,Silver 29,Willemien Aardenburg,F,22,NA,NA,Netherlands,NED,1988 Summer,1988,Summer,Seoul,Hockey,Hockey Women's Hockey,Bronze 30,Pepijn Aardewijn,M,26,189,72,Netherlands,NED,1996 Summer,1996,Summer,Atlanta,Rowing,Rowing Men's Lightweight Double Sculls,Silver 37,Ann Kristin Aarnes,F,23,182,64,Norway,NOR,1996 Summer,1996,Summer,Atlanta,Football,Football Women's Football,Bronze 38,Karl Jan Aas,M,20,NA,NA,Norway,NOR,1920 Summer,1920,Summer,Antwerpen,Gymnastics,Gymnastics Men's Team All-Around Free System,Silver CSE 231 Spring 2019 Edited 03/13/2019: to diplay the best athletes per sport, the table should be sorted by sport alphabetically and by medal counts in descending order. Test 5 was reduced to one plot instead of 2 plots. Programming Project 08 This assignment is worth 50 points (5.0% of the course grade) and must be completed and turned in before 11:59 on Monday, April 1, 2019. Assignment Overview • Dictionaries • Lists and tuples Assignment Background The Olympics happen every 2 years alternating between the summer and winter, where athletes from all over the world come to compete in a variety of sports and events. For this project, you will create a program that will analyze Olympics data over the years about athlete and country information. We’ll be going through the athletes_events.csv file to compare the best athletes in each sport and the top countries for specific sports. Afterwards, we’re going to plot the count of medals over the years for a specific country. Project Specifications You must implement the following functions: a) open_file(): This function prompts the user for the file name as input. It will try to open the file and return the file pointer. If the file is not found, the function must continue asking the user for a file name until the file can be opened and returned. b) get_athlete_stats( ): This function takes in the file pointer as input and skips over the header line. It will iterate through each line in the file and build a dictionary from the data. - Each column in line is separated by commas (since the file is a comma-separated values file). - name, gender, age, height, weight and country_code (column NOC) must be found. - Because of some entries you need to import csv # at the top of your program # in this function reader = csv.reader(fp) # the name “reader” on the left can be any name next(reader,None) # skips one header line, repeat if more header lines for line_list in reader: # reader returns a list - For each line in the file, you need to read the following: name = line_list[1] gender = line_list[2] age = int(line_list[3]) height = int(line_list[4]) weight = int(line_list[5]) CSE 231 Spring 2019 country_code = line_list[7] - All variables must be not null (cannot have ‘NA’ as its value) so ignore any lines without all valid values. (Hint: try-except is one way to do this. Also, “continue” is your friend.) - age, height and weight must be able to be converted to integers. - The dictionary will have the athlete name as its key and a list of tuples as its value. - An athlete can be in the Olympics multiple times and in multiple events so there are multiple entries for athletes, resulting in multiple tuples in lists. - This function will return the dictionary created. - A tuple in the list will have (gender, age, height, weight, country_code) as its content. c) get_country_stats(,
): This function is similar to the get_athlete_stats(fp) function in that it will take in the file pointer and the output from get_athlete_stats() (a dictionary) as input and read each line except the header line. - For each line, the columns must be stripped and separated by the commas (use csv.reader) - The athlete name, team name, country code, year, sport, event and medal variables must be found and stripped. - For each line in the file, you need to read the following: name = line_list[1] # athlete’s name team_name = line_list[6] country_code = line_list[7] year = int(line_list[9]) sport = line_list[12].lower() event = line_list[13].lower() medal = line_list[14].lower() - The sport, event and medal variables must be changed to all lowercase. - All variables we collect must not be null (cannot have ‘NA’ as its value), so ignore any lines without all valid values. . (Hint: try-except is one way to do this. Also, “continue” is your friend.) - The year must be able to be converted to an integer. - The athlete name must be able to be found in the output from get_athlete_stats() , i.e. check that the name is a key in the dictionary. (Hint: use “in”.) - The dictionary that will be output from this function, will have the country_code as its key and a list of tuples as its values. - This function will return the dictionary. - A tuple in the list consists of (name,team_name,year,sport,event,medal). d) display_best_athletes_per_sport(,, ): - This function has 3 inputs: The dictionaries from get_athlete_stats() and get_country_stats() as well as a set of all available sports. Nothing will be returned. - It will need to create a dictionary with the available sports as its keys and a dictionary as its value. - Within the inner dictionary, the athlete name will be used as its key and the number of medals (integer) will be its value. Key = Sport, Value = {: } CSE 231 Spring 2019 - The function will loop through the dictionary from get_country_stats() to find the athlete, sport and medal. Note that when you want to add an athlete for a new sport you need to first create an empty dictionary for that sport before you can add an athlete to it. - The type of medal (gold, silver, bronze) is not relevant for our new dictionary, they will all be treated as 1 medal. - After going through the get_country_stats() dictionary, we want to display a table of: o sport, o best athlete, o code of the country associated with the athlete, and o number of medals the athlete has in the sport. - The table will be sorted by sport only (not athlete’s name). Dictionaries, just like lists, are not always sorted. One way to sort a dictionary is by having a sorted list of keys. To get the list of keys on a dictionary, use the dictionary keys()method. - To find the best athlete, look into sorting the dictionary value for each sport to find the largest medal count and the athlete associated with it. - The country-athlete association can be found in both the athlete and country dictionaries. - There are two header lines. The formatting strings are: "{:^50s}" and "{:<25s}{:25s}{:10s}{:10s}" -="" the="" formatting="" string="" for="" entries="" in="" the="" table="" is="" "{:25.20s}{:25.20s}{:10s}{:10d}"="" at="" the="" end="" of="" the="" table,="" the="" average="" age,="" height="" and="" weight="" for="" the="" best="" athletes="" (i.e.="" the="" ones="" displayed="" in="" the="" table)="" must="" be="" calculated="" and="" displayed.="" draw="" a="" line="" between="" the="" table="" and="" the="" averages="" using:="" print('-'*50)="" -="" within="" the="" dictionary="" from="" get_athlete_stats(),="" each="" athlete’s="" age,="" height="" and="" weight="" can="" be="" found.="" -="" since="" an="" athlete="" can="" be="" in="" the="" olympics="" multiple="" times="" at="" different="" ages,="" heights="" and="" weights,="" find="" the="" average="" age,="" weight="" and="" height="" for="" an="" athlete="" and="" use="" the="" averages="" to="" find="" the="">


Apr 02, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here