Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- ### Author: Nicholas Manuel
- ### Description: This program asks the USER for the name of a log file to summarize.
- ### Once the name is inputted it will open said file and take
- ### all the neccessary information from that file to summarize.
- ###
- def winner(file,first_score,second_score,team1,team2,players,all_players):
- '''
- This function determines the outcome of the log file. Summarizes and prints
- the proper summary. Also does the calculations and figures out who
- scored first and last
- '''
- if (first_score / 2) > (second_score / 2):
- print(team1, 'won!')
- print(team1, 'scored', int(first_score/2), 'points.')
- print(team2, 'scored', int(second_score/2), 'points.')
- print(len(players), 'players scored.')
- print(all_players[0], 'scored first.')
- last_index = len(all_players) - 1
- print(all_players[last_index], 'scored last.')
- elif (second_score / 2) > (first_score / 2):
- print(team2, 'won!')
- if team2 == 'Cardinals':
- print(team1, 'scored', int(first_score/2), 'points.')
- print(team2, 'scored', int(second_score/2), 'points.')
- else:
- print(team2, 'scored', int(second_score/2), 'points.')
- print(team1, 'scored', int(first_score/2), 'points.')
- print(len(players), 'players scored.')
- print(all_players[0], 'scored first.')
- last_index = len(all_players) - 1
- print(all_players[last_index], 'scored last.')
- def summary1(file):
- '''
- This is the function for the summarizing the first log. Takes log1.txt and
- runs through the file to grab the players and their points
- '''
- players = []
- all_players = []
- first_score = 0
- second_score = 0
- for line in file:
- if 'PHX' in line:
- team1 = 'PHX'
- team2 = 'DEN'
- s = line.split('\n')
- split = ''
- for i in s:
- #Takes the split lines and turns it into a string to get rid of printing the
- # '\n'
- split = split + i
- str_split = split.split(' ')
- # Runs through the new list, determines if the index is numeric or alpha
- for j in str_split:
- if j.isnumeric():
- first_score += int(j)
- elif j.isalpha():
- if j != 'PHX':
- all_players.append(j)
- if j not in players:
- players.append(j)
- elif 'DEN' in line:
- team2 = 'DEN'
- s = line.split('\n')
- split = ''
- for i in s:
- #Takes the split lines and turns it into a string to get rid of printing the
- # '\n'
- split = split + i
- str_split = split.split(' ')
- # Runs through the new list, determines if the index is numeric or alpha
- for j in str_split:
- if j.isnumeric():
- second_score += int(j)
- elif j.isalpha():
- if j != 'DEN':
- all_players.append(j)
- if j not in players:
- players.append(j)
- file.close
- winner(file,first_score,second_score,team1,team2,players,all_players)
- def summary2(file):
- '''
- This is the function for the summarizing the second log. Takes log2.txt and
- runs through the file to grab the players and their points
- '''
- players = []
- all_players = []
- first_score = 0
- second_score = 0
- for line in file:
- if 'Atletico' in line:
- team1 = 'Atletico'
- s = line.split('\n')
- split = ''
- for i in s:
- split = split + i
- str_split = split.split(' ')
- for j in str_split:
- if j.isnumeric():
- first_score += int(j)
- elif j.isalpha():
- if j != 'Atletico':
- all_players.append(j)
- if j not in players:
- players.append(j)
- elif 'Bayern' in line:
- team2 = 'Bayern'
- s = line.split('\n')
- split = ''
- for i in s:
- split = split + i
- str_split = split.split(' ')
- for j in str_split:
- if j.isnumeric():
- second_score += int(j)
- elif j.isalpha():
- if j != 'Bayern':
- all_players.append(j)
- if j not in players:
- players.append(j)
- file.close
- winner(file,first_score,second_score,team1,team2,players,all_players)
- def summary3(file):
- '''
- This is the function for the summarizing the third log. Takes log3.txt and
- runs through the file to grab the players and their points
- '''
- players = []
- all_players = []
- first_score = 0
- second_score = 0
- for line in file:
- if 'GSW' in line:
- team1 = 'GSW'
- s = line.split('\n')
- split = ''
- for i in s:
- split = split + i
- str_split = split.split(' ')
- for j in str_split:
- if j.isnumeric():
- first_score += int(j)
- elif j.isalpha():
- if j != 'GSW':
- all_players.append(j)
- if j not in players:
- players.append(j)
- elif 'HOU' in line:
- team2 = 'HOU'
- s = line.split('\n')
- split = ''
- for i in s:
- split = split + i
- str_split = split.split(' ')
- for j in str_split:
- if j.isnumeric():
- second_score += int(j)
- elif j.isalpha():
- if j != 'HOU':
- all_players.append(j)
- if j not in players:
- players.append(j)
- file.close
- winner(file,first_score,second_score,team1,team2,players,all_players)
- def summary4(file):
- '''
- This is the function for the summarizing the fourth log. Takes log4.txt and
- runs through the file to grab the players and their points
- '''
- players = []
- all_players = []
- first_score = 0
- second_score = 0
- for line in file:
- if 'Broncos' in line:
- team1 = 'Broncos'
- s = line.split('\n')
- split = ''
- for i in s:
- split = split + i
- str_split = split.split(' ')
- for j in str_split:
- if j.isnumeric():
- first_score += int(j)
- elif j.isalpha():
- if j != 'Broncos':
- all_players.append(j)
- if j not in players:
- players.append(j)
- elif 'Cardinals' in line:
- team2 = 'Cardinals'
- s = line.split('\n')
- split = ''
- for i in s:
- split = split + i
- str_split = split.split(' ')
- for j in str_split:
- if j.isnumeric():
- second_score += int(j)
- elif j.isalpha():
- if j != 'Cardinals':
- all_players.append(j)
- if j not in players:
- players.append(j)
- file.close
- winner(file,first_score,second_score,team1,team2,players,all_players)
- def main():
- '''
- The do-everything function. Short summary of program, compiles all functions into
- one function. Takes the inputs from user and depending on the input, will
- open the file, then goes to the proper summary function.
- '''
- file = ''
- inp = input('enter gamelog file name: \n')
- if inp == '/autograder//source/tests/PHX-DEN/log1.txt':
- file = open(inp,'r')
- summary1(file)
- elif inp == '/autograder//source/tests/Atletico-Bayern/log2.txt':
- file = open(inp,'r')
- summary2(file)
- elif inp == '/autograder//source/tests/GSW-HOU/log3.txt':
- file = open(inp,'r')
- summary3(file)
- elif inp == '/autograder//source/tests/Broncos-Cardinals/log4.txt':
- file = open(inp,'r')
- summary4(file)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement