Question: Specification Create the function team_average which has the following header def team_average (filename): This function will return the average number of games won by the

 Specification Create the function team_average which has the following header defteam_average (filename): This function will return the average number of games won

Specification Create the function team_average which has the following header def team_average (filename): This function will return the average number of games won by the Red Sox from a text file with entries like this 2011-07-02 2011-07-03 2011-07-04 Red Sox 2 Astros Red Sox Astros Red Sox vs Blue Jays Win 7-5 Win 2-1 Loss 7-9 This function should create a file object for the file whose name is given by the parameter filename. If the file cannot be opened, use a try/except statement to print an error message and don't do any further work on the file The function will count the number of lines and the number of games the Red Sox won and use these values to compute the average games won by the team This average should be expressed as an integer Your hw2.py file must contain the following test code at the bottom of the file team_average('xxxxxxx') print (team_average( 'red sox.txt')) Suggestions Write this program in a step-by-step fashion using the technique of incremental development In other words, write a bit of code, test it, make whatever changes you need to get it working, and go on to the next step 1. Write the function code to open the file for reading. This code should print an error message and exit the function if the file cannot be opened for reading 2. Modify the function so it prints out the lines of the file 3. Modify the function to use the split string method to create a list from the from the different fields in a line. Print this list 4. For each line, get the value of the won/lost field and print it This field is second to last entry in the list you created by using the splitmethod

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!