Skip to content

Instantly share code, notes, and snippets.

@EdwardReed
Created November 8, 2012 15:24
Show Gist options
  • Save EdwardReed/4039444 to your computer and use it in GitHub Desktop.
Save EdwardReed/4039444 to your computer and use it in GitHub Desktop.
pa7
# Author: Edward Reed
# CLID: exr3920
# Course/Section: CMPS 150 -- Section 001
# Assignment: pa7
# Date Assigned: Friday, November 2, 2012
# Date/Time Due: Wednesday, November 7, 2012 - 11:55 pm
#
# Description: Will output all read as well as the player's batting average.
#
# Certification of Authenticity:
# I certify that this assignment is entirely my own work.
def head():
print("{0:25}{1:25}{2:9}{3:7}{4:6}{5:6}{6:7}".format("Player","Team"," At Bats","Hits","Walks","Avg","OnBase%"))
print("-"*90)
def main():
#getting input
inFile = open("baseball","r")
head()
highest_avg = 0
lowest_BB = 100000
total_BB = 0
total_avg = 0
bats = 0
hits = 0
for i in range(6):
#processing data
data = inFile.readline()
data = data.split(",")
avg = round((eval(data[3])/eval(data[2])*1000), 1)
hits = eval(data[3]) + hits
bats = eval(data[2]) + bats
walks = eval(data[4])
onBase = eval(data[3]) + walks
onBase = onBase / (eval(data[2]) + eval(data[4]))
onBase = onBase * 1000
print("{0:25}{1:25}{2:8}{3:7}{4:5}{5:7}{6:7}".format(data[0],data[1],data[2],data[3],walks,round(avg,1),round(onBase,1)))
if avg > highest_avg:
highest_avg = avg
highest_avgName = data[0]
if eval(data[4]) < lowest_BB:
lowest_BB = eval(data[4])
lowest_BBName = data[0]
total_BB = total_BB + eval(data[4])
total_avg = total_avg + avg
over_avg = round(hits / bats * 1000,1)
inFile.close
print("-"*90)
print()
#outputting results
print("Highest AVG: ",highest_avgName," : ",highest_avg)
print("Fewest BB: ",lowest_BBName," : ",lowest_BB)
print("Total BB: ",total_BB)
print("Overall AVG: ",over_avg)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment