Feb-09-2017, 11:38 AM
Buran/oFnuts,
Per your advise, I changed the code as shown below and i got a bunch of error
Per your advise, I changed the code as shown below and i got a bunch of error
def team_average(filename): numberOfGames = 0 soxWins = 0 try: file = open(filename, 'r') except: print (filename, "Cannot be opened") else: for line in file: numberOfGames += 1 game = line.split() scores = game[1] scores_list = scores.split('-') for score in scores_list: if (int(score[0]) - int(score[1]) > 0: soxWins += 1 average_win = int(soxWins/numberOfGames) * 100 team_average('xxxxxx') print(team_average('red_sox.txt'))and below is the error i got :
Quote:Traceback (most recent call last):
File "./hw2.py", line 25, in <module>
print(team_average('red_sox.txt'))
File "./hw2.py", line 20, in team_average
if int(score[0]) - int(score[1]) > 0:
ValueError: invalid literal for int() with base 10: 'R'