Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you help me write the Python Code for Question 2? Shoumik is trying to analyze how well the Cal football team performed in the
Can you help me write the Python Code for Question 2?
Shoumik is trying to analyze how well the Cal football team performed in the 2019 season. A football game is divided into four periods, called quarters. The number of points Cal scored in each quarter, and the number of points their opponent scored in each quarter are stored in a table called cal_fb.csv. In [5]: # Just run this cell # Read in the cal_fb csv file games = Table().read_table("cal_fb.csv") games.show() Opponent Cal 1Q Cal 20 Cal 3Q Cal 4Q Opp 1Q Opp 20 Opp 3Q Opp 40 UC Davis 0 13 7 7 10 0 3 0 Washington D 3 14 3 0 10 3 6 North Texas 200 3 0 0 3 7 7 Ole Miss 7 7 14 0 7 6 0 7 Arizona State 7 0 7 3 7 0 7 10 Oregon 7 0 0 0 0 0 10 Oregon State 3 14 0 7 7 0 Utah 0 0 0 7 217 Washington State 7 7 13 5 6 3 USC 3 0 7 10 7 17 Stanford 14 7 3 7 UCLA 7 7 7 Illinois 7 14 7 7 10 3 0 7 Let's start by finding the total points each team scored in a game. Let's start by finding the total points each team scored in a game. Question 1. Write a function called sum_scores . It should take four arguments, where each argument is the team's score for that quarter. It should return the team's total score for that game. In [6]: def sum_scores(a,b,c,d): ''Returns the total score calculated by adding up the score of each quarter'' sum= a + b + c + d print(sum) sum_scores(14, 7, 3, 0) #DO NOT CHANGE THIS LINE Question 2. Create a new table final_scores with three columns in this specific order: Opponent , Cal Score , Opponent Score . You will have to create the Cal Score and Opponent Score columns. Use the function sum_scores you just defined in the previous question for this problem. Hint: If you want to apply a function that takes in multiple arguments, you can pass multiple column names as arguments in tbl.apply() . The column values will be passed into the corresponding arguments of the function. Take a look at the python reference for syntax. Tip: If you're running into issues creating final_scores, check that cal_scores and opponent_scores output what you want. In [6]: cal_scores = ... opponent_scores = .. final_scores = ... final_scores Shoumik is trying to analyze how well the Cal football team performed in the 2019 season. A football game is divided into four periods, called quarters. The number of points Cal scored in each quarter, and the number of points their opponent scored in each quarter are stored in a table called cal_fb.csv. In [5]: # Just run this cell # Read in the cal_fb csv file games = Table().read_table("cal_fb.csv") games.show() Opponent Cal 1Q Cal 20 Cal 3Q Cal 4Q Opp 1Q Opp 20 Opp 3Q Opp 40 UC Davis 0 13 7 7 10 0 3 0 Washington D 3 14 3 0 10 3 6 North Texas 200 3 0 0 3 7 7 Ole Miss 7 7 14 0 7 6 0 7 Arizona State 7 0 7 3 7 0 7 10 Oregon 7 0 0 0 0 0 10 Oregon State 3 14 0 7 7 0 Utah 0 0 0 7 217 Washington State 7 7 13 5 6 3 USC 3 0 7 10 7 17 Stanford 14 7 3 7 UCLA 7 7 7 Illinois 7 14 7 7 10 3 0 7 Let's start by finding the total points each team scored in a game. Let's start by finding the total points each team scored in a game. Question 1. Write a function called sum_scores . It should take four arguments, where each argument is the team's score for that quarter. It should return the team's total score for that game. In [6]: def sum_scores(a,b,c,d): ''Returns the total score calculated by adding up the score of each quarter'' sum= a + b + c + d print(sum) sum_scores(14, 7, 3, 0) #DO NOT CHANGE THIS LINE Question 2. Create a new table final_scores with three columns in this specific order: Opponent , Cal Score , Opponent Score . You will have to create the Cal Score and Opponent Score columns. Use the function sum_scores you just defined in the previous question for this problem. Hint: If you want to apply a function that takes in multiple arguments, you can pass multiple column names as arguments in tbl.apply() . The column values will be passed into the corresponding arguments of the function. Take a look at the python reference for syntax. Tip: If you're running into issues creating final_scores, check that cal_scores and opponent_scores output what you want. In [6]: cal_scores = ... opponent_scores = .. final_scores = ... final_scoresStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started