Good that you solved it.
Some points,average is a confusing name when you calculate percentage
Do not use bare
Eg:
Some points,average is a confusing name when you calculate percentage

Do not use bare
except:
and return out when error occurred.Eg:
def team_average(filename): try: file = open(filename) except IOError as error: return error else: numberOfGames = 0 soxWins = 0 for line in file: numberOfGames += 1 game = line.split() scores = game[-2] if scores == 'Win': soxWins += 1 win_percent = int((soxWins/numberOfGames) * 100) return win_percent print(team_average('red_sox.txt'))Alternative way and a little more Pythonic could be:
with open('red_sox.txt') as file: all_games = [line for line in file] win = [game for game in all_games if 'Win' in game] win_percent = len(win) / len(all_games) * 100 print(win_percent)