ef getLists(): # Create a Variable to ask the user to get the file fname = input("Enter the name of the MLB stats data file: ") infile = open(fname, 'r') # Creates lists for the text file players = [] teams = [] positions = [] runs = [] hits = [] homeruns = [] averages = [] line = infile.readline() for line in infile: line = line.strip() player, team, position, run, hit, homerun, average = line.split(',') players = players + [player] teams = teams + [team] positions = positions + [position] runs = runs + [run] hits = hits + [int(hit)] homeruns = homeruns + [int(homerun)] averages = averages + [float(average)] return players, teams, positions, runs, hits, homeruns, averages # Find's the player with the highest average def getHighestAverage(players, averages): highestAverage = 0 for i in range(len(averages)): if highestAverage >= averages[i]: highestAverage = [i] print(players[highestAverage],averages[highestAverage])
if highestAverage >= averages[i]: highestIndex= i highestAverage= averages[i] print(players[highestIndex], averages[highestIndex])
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)