# 1. Create a list of 5 lists, where each list contains 4 statistics. # [FGM, FG
ID: 3733744 • Letter: #
Question
# 1. Create a list of 5 lists, where each list contains 4 statistics.
# [FGM, FGA, 3PM, 3PA] -- This list holds these stats from a single Game.
# You should have one list of 5 lists with the stats above from the website.
stats = [[4, 12, 3, 6],
[5, 9, 2, 6],
[2, 12, 1, 6],
[4, 8, 2, 5],
[1, 3, 1, 2]]
# 2. Create a function called efg_percentage that has one parameter (a list)
# and returns the effective field goal percentage (efg).
# HINT: You do NOT need to put square braces around the parameter.
# The efg_percentage function should calculate efg using the following formula:
#
#
# efg = (FMG + 1.5 * 3PM) / (FGA + 3PA)
#
# You will need to figure out how to access each of the stats required inside the function.
efg_percentage()
# 3. Use a for loop to call the efg_percentage function so that it prints
# the efg for every game. See the .png in the assignment for the output example.
Explanation / Answer
def efg_percentage(list): FMG = list[0] FGA = list[1] PM = list[2] PA = list[3] efg = (FMG + 1.5 * PM) / (FGA + PA) return efg stats = [[4, 12, 3, 6], [5, 9, 2, 6], [2, 12, 1, 6], [4, 8, 2, 5], [1, 3, 1, 2]] for i in range(len(stats)): print(efg_percentage(stats[i]))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.