Question: (PYTHON) Given input data in the form [team_name, wins, losses, ties], write a function that computes the following score: (wins+1/2 ties)/total_number_of_games Write a function that
(PYTHON) Given input data in the form [team_name, wins, losses, ties], write a function that computes the following score: (wins+1/2 ties)/total_number_of_games
Write a function that prints each team name followed by the score
Write a function that uses this Score to sort the teams from highest to lowest score. See the homework_sort.py program we discussed in class
homework1=[['IntroCS', 2, 'Maj', 3],['Botany',4,'Elect',1],\ ['Calc',5,'Elect',4],['ArtHist',1,'Min',1],['CircArts',7,'Maj',1]] ## homework1 is for a student who is taking a double major ## in Circus Arts and Computer Science, with a minor in Art History. ## the order is [subject, due_in_days, Maj/Min/Elect, hours_to_do] def score_homework(homework): ## a lower score means do this first subject,due_in_days,Maj_min,hours_to_do = homework ## favor homework that is quick to do and/or is due sooner score = due_in_days*hours_to_do ## if Maj_min == 'Maj': score = score*.5 elif Maj_min == 'Min': score = score*.75 ## favor homework for major and minor over electives return(score) def sort_homework(homework_list): print(homework_list) list_to_sort = [] for homework in homework_list: print(homework) list_to_sort.append([score_homework(homework),homework]) list_to_sort.sort() return(list_to_sort) print('version1',sort_homework(homework1)) def sort_homework2(homework_list): ## fancier syntax, but does not include the ## score used for sorting in the output print(homework_list) list_to_sort = [] homework_list.sort(key=lambda homework: score_homework(homework)) return(homework_list) print('version2',sort_homework2(homework1)) Use the following as sample list of input: Input_Data = [['Mets',10,5,5], ['Yankees',11,2,2], ['Bears',7,15,0], ['Senators',5,30,1], ['Clowns',10,50,1]]
Hint: Sort orders from lowest score to highest. The above score favors large numbers. So sorting will order the teams exactly backwards (the teams would be ordered from worst to best). One way to get around this problem is to sort using the above score and then use the list.reverse() method to make reverse the list and order the teams from best to worst. Another way to get around this would be to modify the scores above, multiplying each by -1, before putting them at the front of the lists in the style of the homewor_sort program. Either way, the ordering would be from lowest to highest.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
