""" league_dict = {rpi_0,wins_1,total games_2, opponents played as a list_3} """ league_dict = {'JMU': [0,0,0,[]] , 'DEPAUL': [0,0,0,[]] , 'KENT': [0,0,0,[]], 'UK': [0,0,0,[]] , 'UMD': [0,0,0,[]] , 'TU': [0,0,0,[]] , 'OSU': [0,0,0,[]] , 'WKU': [0,0,0,[]] , 'MBI': [0,0,0,[]] , 'MSU': [0,0,0,[]] , 'GVSU': [0,0,0,[]] , 'K-STATE': [0,0,0,[]] , 'BGSU': [0,0,0,[]] , 'SVSU': [0,0,0,[]] , 'UWP': [0,0,0,[]] , 'CMU': [0,0,0,[]] , 'MIAMI': [0,0,0,[]] , 'UOFL': [0,0,0,[]] , 'EMU': [0,0,0,[]] , 'NSULA': [0,0,0,[]] , 'WIU': [0,0,0,[]] , 'LCC': [0,0,0,[]] , 'UNL': [0,0,0,[]] , 'RIT': [0,0,0,[]] , 'VCU': [0,0,0,[]] , } """ main: used for input """ def main(league_dict = league_dict): for team in league_dict : print "Enter WINS for ", team, ":" wins = raw_input("") league_dict[team][1] = wins print "Enter TOTAL GAMES PLAYED for ", team, ":" TGP = raw_input("") league_dict[team][2] = TGP opp_team = 's' while opp_team != "DONE": print" Enter oppenent team for" , team, "enter 'done' to move to next team" opp_team = raw_input("") opp_team = opp_team.upper() if opp_team in league_dict: league_dict[team][3].append(opp_team) elif opp_team == "DONE": pass else: print "Enter valid team" print " " for school in league_dict: calc_RPI(school) print_it() """ get_WP: calculates a team's winning percentage """ def get_WP(school,league_dict = league_dict): try: WP = float(league_dict[school][1]) / float(league_dict[school][2]) except ZeroDivisionError: WP = 0 return WP """ calc_RPI: calculate teams RPI """ def calc_RPI(school,league_dict = league_dict): school_WP = get_WP(school) count_o = 0 #opponent count_oo = 0#opponents opponent OWP = 0 #opponents WP OOWP = 0 #opponents opponent WP for opponent in league_dict[school][3]: #parse thru opponents count_o += 1 OWP += get_WP(opponent) for oo in league_dict[opponent][3]: #parse thru opponents opponents count_oo +=1 OOWP += get_WP(oo) OWP = float(OWP)/float(count_o) #averages opponents WP OOWP = float(OOWP)/float(count_oo)# averages opponents opponents WP RPI = (school_WP*0.25) + (OWP*0.50) + (OOWP*0.25) league_dict[school][0] = RPI return league_dict """ print_it: prints out rankings in order """ def print_it(league_dict = league_dict): for team in league_dict: print team, "wins: " , league_dict[team][1], "total games: ",\ league_dict[team][2], "teams played: ", league_dict[team][3] rank_list = [] for school,value in league_dict.items(): rank_list.append([value[0],school]) rank_list.sort() rank_list.reverse() rank = 0 for school in rank_list: rank+=1 print '#',rank, school main()