Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It' ootobor. whioh means ite baseball playoffe 6oason! in thie oxoroice, let' utilizo diotionarios to soo if we can' model and learn more about saome

image text in transcribed

It' ootobor. whioh means ite baseball playoffe 6oason! in thie oxoroice, let' utilizo diotionarios to soo if we can' model "and learn more "about saome of Our favorite playersin thia problem, you will b As you oan see within your hw06.py file-the dictionaries mapping players to their team and statistis If you're a Moneyball movie fan, you know that statistics helps teams find value in players that nobody else sees. In this problem, you'll be implementing two functions to calculate the team batting average for one team, and the mean slugging percentage for all teams. full-roster = { "Manny Machado" Dodgers". Dodgers We highly encourage you to use the functions that you've defined before to solve these problems, specifically the common_players and get players functions from the previous two problems. Two functions have already been defined for you to calculate batting average and slugging percentage given a player's statistics. Use these functions when you calculate the averages for each team. *CLayton Kershaw"Dodgers". Giancarto Stanton""Yankees' fullstots- "Manny Machado so". 13"SO".HR 1. Aaron Judge""SO"."HR"HR"18". S0, CLoyton Kershow"1B # Following Functions have been given to you, do NOT modify def get team(pLayer) def calculate batting_average(stats): Returns tcam that the provided ployer is o member of hits 0 total_bats 0 for at bat in stats: get.team"Manny Machado" get team"Aaron Judge" if at bat "S0": ERE hits += 1 return full roster player) totalbats += 1 - det get_ stots(player I return float (round (hits/total_bats, 1)) Returns the statistics associated with the provided player get stats'Manny Machado" def calculate slugging_ percent(stats): get statsAaron 3udge bases0 total_bats0 for at_bat in stats: ERE return full stats(player) if at bat"1B" bases += 1 Question 2: Team Roster elif at_bat"2B": Impiemant tha funct on get_ptayers which takas a team name and enuns a list containing all tha playwars that are membars of the given team. bases +2 elif atbat --"3B". - def get_players team: bases 3 elif at_bat"HR" bases+ 4 ""Returns a list of all players who are rembers of the given tean. get players("Dodgers") T'Manny Machado 'Yasiel Puig' 'Clayton Kershaw' totalbats +-1 - get players("Yankees" return float (round (bases/total_bats, 1)) ['Aaron Judge', 'Giancarlo Stanton 1 YOUR CODE HERE # Modify Functions below def calculate team BA(team): mplement the function connon players.The common_players function identifiee which keys fom he full roster share the same values. The function returns a new cictionary where each key is the value from the criginal dictionary, and the corresponding values of the new dictionary are list that cotain keys that share the same value " "Given a single team name, returns the mean batting average of all pl calculate team BA( 'Dodgers calculate team_BA( 'Yankees') det connon players( raster 0.6 Returns a dictionary containing values along with a corresponding list of keys that had that value fron the original dictionary "YOUR CODE HERE return comnon players(full_roster) 'Dodgers:'Manny Machado 'Yasiel Puig'"Clayton Kershaw Yanke fullraster T"bob": "excellent", "barnum": "passing", "beatrice: comnon players(full_roster) def calculate_all_team_SP): 'excellent: 'bob 'bel"baxter', 'passing': 'barnun', 'bernice " Returns a dictionary mapping every team to the average slugging perce calculate all_team_SPC) Dodgers' 1.2, 'Yankees' 1.8) "scex YOUR CODE HERE " YOUR CODE HERE return It' ootobor. whioh means ite baseball playoffe 6oason! in thie oxoroice, let' utilizo diotionarios to soo if we can' model "and learn more "about saome of Our favorite playersin thia problem, you will b As you oan see within your hw06.py file-the dictionaries mapping players to their team and statistis If you're a Moneyball movie fan, you know that statistics helps teams find value in players that nobody else sees. In this problem, you'll be implementing two functions to calculate the team batting average for one team, and the mean slugging percentage for all teams. full-roster = { "Manny Machado" Dodgers". Dodgers We highly encourage you to use the functions that you've defined before to solve these problems, specifically the common_players and get players functions from the previous two problems. Two functions have already been defined for you to calculate batting average and slugging percentage given a player's statistics. Use these functions when you calculate the averages for each team. *CLayton Kershaw"Dodgers". Giancarto Stanton""Yankees' fullstots- "Manny Machado so". 13"SO".HR 1. Aaron Judge""SO"."HR"HR"18". S0, CLoyton Kershow"1B # Following Functions have been given to you, do NOT modify def get team(pLayer) def calculate batting_average(stats): Returns tcam that the provided ployer is o member of hits 0 total_bats 0 for at bat in stats: get.team"Manny Machado" get team"Aaron Judge" if at bat "S0": ERE hits += 1 return full roster player) totalbats += 1 - det get_ stots(player I return float (round (hits/total_bats, 1)) Returns the statistics associated with the provided player get stats'Manny Machado" def calculate slugging_ percent(stats): get statsAaron 3udge bases0 total_bats0 for at_bat in stats: ERE return full stats(player) if at bat"1B" bases += 1 Question 2: Team Roster elif at_bat"2B": Impiemant tha funct on get_ptayers which takas a team name and enuns a list containing all tha playwars that are membars of the given team. bases +2 elif atbat --"3B". - def get_players team: bases 3 elif at_bat"HR" bases+ 4 ""Returns a list of all players who are rembers of the given tean. get players("Dodgers") T'Manny Machado 'Yasiel Puig' 'Clayton Kershaw' totalbats +-1 - get players("Yankees" return float (round (bases/total_bats, 1)) ['Aaron Judge', 'Giancarlo Stanton 1 YOUR CODE HERE # Modify Functions below def calculate team BA(team): mplement the function connon players.The common_players function identifiee which keys fom he full roster share the same values. The function returns a new cictionary where each key is the value from the criginal dictionary, and the corresponding values of the new dictionary are list that cotain keys that share the same value " "Given a single team name, returns the mean batting average of all pl calculate team BA( 'Dodgers calculate team_BA( 'Yankees') det connon players( raster 0.6 Returns a dictionary containing values along with a corresponding list of keys that had that value fron the original dictionary "YOUR CODE HERE return comnon players(full_roster) 'Dodgers:'Manny Machado 'Yasiel Puig'"Clayton Kershaw Yanke fullraster T"bob": "excellent", "barnum": "passing", "beatrice: comnon players(full_roster) def calculate_all_team_SP): 'excellent: 'bob 'bel"baxter', 'passing': 'barnun', 'bernice " Returns a dictionary mapping every team to the average slugging perce calculate all_team_SPC) Dodgers' 1.2, 'Yankees' 1.8) "scex YOUR CODE HERE " YOUR CODE HERE return

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions