We appreciate your visit to Using the data provided generate a report of a player s batting average and slugging percentage by month Use Python to perform the following tasks. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
Answer :
Answer:
Check the explanation
Explanation:
with open('stats. txt', 'r') as # open the file in read mode
list1 = [] # initialize an empty list
for i in . readlines (): # read every line of file
for j in i. split (): # split each line by a space and append it to the list1
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 list1 elements to required lists
plate_apperence. append(int(list1[i+1]))
at_bats. append(int(list1[i+2]))
runs. append(int(list1[i+3]))
hits. append(int(list1[i+4]))
total_bats. append(int(list1[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("\n")
Kindly check the attached images below to get the Code Screenshot and Code Output.
Thanks for taking the time to read Using the data provided generate a report of a player s batting average and slugging percentage by month Use Python to perform the following tasks. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada