#This program reads the data in AU gamedata.csv and calculates averages import csv def myavg(score, games): return score / games cvscore, chscore, cvnum, chnum = 0, 0, 0, 0 nvscore, nhscore, nvnum, nhnum = 0, 0, 0, 0 tvscore, thscore, tvnum, thnum = 0, 0, 0, 0 #Read the data from the file to be read reader = csv.reader(open('AUGamedata.csv', 'r'), delimiter=',') #Process each row for row in reader: datarow = list(row) score = int(datarow[3]) if datarow[1] == 'C': if datarow[2] == 'V': cvscore += score cvnum += 1 else: chscore += score chnum += 1 elif datarow[1] == 'N': if datarow[2] == 'V': nvscore += score nvnum += 1 else: nhscore += score nhnum += 1 else: if datarow[2] == 'V': tvscore += score tvnum += 1 else: thscore += score thnum += 1 print('Average points per game') print('Home team, nonconference: %4.2f \tNo of games: %s' % (myavg(nhscore, nhnum), nhnum)) print('Home team, conference: %4.2f \t\tNo of games: %s' % (myavg(chscore, chnum), chnum)) print('Home team, tournament: %4.2f \t\tNo of games: %s'% (myavg(thscore,thnum), thnum)) print('Visiting team, nonconference: %4.2f \tNo of games: %s' % (myavg(nvscore, nvnum), nvnum)) print('Visiting team, conference: %4.2f \tNo of games: %s' % (myavg(cvscore, cvnum), cvnum)) print('Visiting team, tournament: %4.2f \tNo of games: %s' % (myavg(tvscore, tvnum), tvnum)) vscore = cvscore + nvscore + tvscore vgames = cvnum + nvnum + tvnum hscore = chscore + nhscore + thscore hgames = chnum + nhnum + thnum tscore = vscore + hscore tgames = vgames + hgames print('Overall home team average: %4.2f \tNo of games: %s' % (myavg(hscore, hgames), hgames)) print('Overall visiting team average: %4.2f \tNo of games: %s' % (myavg(vscore, vgames), vgames)) print('Overall average: %4.2f \t\t\tNo of games: %s' % (myavg(tscore, tgames), tgames))