#This program reads the data in AU gamedata.csv and calculates averages import csv 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 cvavg = cvscore / cvnum chavg = chscore / chnum nvavg = nvscore / nvnum nhavg = nhscore / nhnum tvavg = tvscore / tvnum thavg = thscore / thnum print('Average points per game') print('Home team, nonconference: %4.2f \tNo of games: %s' % (nhavg, nhnum)) print('Home team, conference: %4.2f \t\tNo of games: %s' % (chavg, chnum)) print('Home team, tournament: %4.2f \t\tNo of games: %s'% (thavg, thnum)) print('Visiting team, nonconference: %4.2f \tNo of games: %s' % (nvavg, nvnum)) print('Visiting team, conference: %4.2f \tNo of games: %s' % (cvavg, cvnum)) print('Visiting team, tournament: %4.2f \tNo of games: %s' % (tvavg, tvnum)) vscore = cvscore + nvscore + tvscore vgames = cvnum + nvnum + tvnum hscore = chscore + nhscore + thscore hgames = chnum + nhnum + thnum ovavg = vscore / vgames ohavg = hscore / hgames tscore = vscore + hscore tgames = vgames + hgames oavg = tscore / tgames print('Overall home team average: %4.2f \tNo of games: %s' % (ohavg, hgames)) print('Overall visiting team average: %4.2f \tNo of games: %s' % (ovavg, vgames)) print('Overall average: %4.2f \t\t\tNo of games: %s' % (oavg, tgames))