Feb-09-2017, 02:58 PM
So i finally got the code right and below is my final code :
Thanks a lot gentlemen
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[-2] if scores == 'Win': soxWins += 1 average_win = int((soxWins/numberOfGames) * 100) return average_win team_average('xxxxxx') print(team_average('red_sox.txt'))I learned a lot just from this thread of course with your tremendous help. Below are some of the acquired knowledge:
- Troubleshoot the code using the print statement
- avoid the use of the exception any how and everywhere, it can hide errors.
- indentation issue
- Usage of the for loop
- Etc...
Thanks a lot gentlemen