Question: Please use Spyder Coding Tool! Please use Spyder Coding Tool! Please use Spyder Coding Tool! I am getting an error in this code.. Please help!

Please use Spyder Coding Tool!

Please use Spyder Coding Tool!

Please use Spyder Coding Tool!

I am getting an error in this code.. Please help!

Please use Spyder Coding Tool! Please use Spyder

STATS:

April 107 90 29 31 66 May 106 94 23 35 72 June 77 62 12 18 29 July 115 103 20 34 59 August 124 102 25 36 63 September 85 69 20 26 44

Please use Spyder Coding Tool! Please use Spyder

I am getting an error in this code.. Please help!

Coding 5: File Input, Output (14 points) Using the attached stats.txt, generate a report of a player's batting average using hits / at bats by month and slugging percent by dividing total bases by at bats. Print out each month, number hits, number of at bats , BA (batting average) and slugging percent (). The input file is organized by month, plate appearances, at bats, runs, hits and total bases. A Ewith open('stats.txt', 'r') as f: # open the file in read mode list1 = [] # initialize an empty list for i in f.readlines(): # read every line of file for j in i.split(): # split each line by a space and append it to the listi list1.append(j) months = [] # initialize required lists to empty list plate_apperence = [] at_bats = [] runs = [] hits = [] total_bats = [] for i in range(0, len(list1)-1, 7): # use a for loop and give parameters as start, stop and step count months.append(list1[i]) # append listi elements to required lists plate_apperence.append(int(list1[i+1])) at_bats.append(int(list1[i+2])) runs.append(int(listi[i+3])) hits.append(int(listi[i+4])). total_bats.append(int(listi[i+5])) for i in range(len (months)): # for each element in months print("Player's Average Batting and slugging percent for the month ", months[i], " is as shown below") print("{:.2f}".format(hits[i]/at_bats[i])) # calculate Average batting and slugging percent and print them print("{:.2f}".format(total_bats[i]/at_bats[i])) print(" ")

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 General Management Questions!