Takes a team id and returns that team’s first serve win fraction.
team_id_test ='T2't = Team(team_id_test)team_win_frac_test = t.num_games_won/t.num_games_playedprint("{} won {:.2f}% of games they played".format(get_team_name(team_id_test), team_win_frac_test*100))
Anna Leigh Waters & Leigh Waters won 66.67% of games they played
Let’s look at the win percentage when serving first, marginalized over all games
#Find the teams that Jesse Irvine played forteam_ids_test = get_teams_from_player(player_id_test)for team_id in team_ids_test:print(get_team_name(team_id))
Returns the number of games played by a team with team_id.
net_games_played =sum([games_played_by_team(team_id) for team_id in team_ids_test]) #Number of games played by Jesse Irvine on any teamavg_first_serve_win_frac_test =sum([team_first_serve_win_frac(team_id)* games_played_by_team(team_id) for team_id in team_ids_test])/net_games_played #Average first serve win frac for Jesse Irvineavg_tot_win_frac_test =sum([team_win_frac(team_id)* games_played_by_team(team_id) for team_id in team_ids_test])/net_games_played #Average total win frac for Jesse Irvineprint("{}'s average first serve win percentage is {:.2f}%".format(player_name_test, avg_first_serve_win_frac_test*100))print("{}'s average overall win percentage is {:.2f}%".format(player_name_test, avg_tot_win_frac_test*100))
Jesse Irvine's average first serve win percentage is 33.33%
Jesse Irvine's average overall win percentage is 66.67%