Skip to content

Instantly share code, notes, and snippets.

@earthling-shruti
Created February 14, 2013 08:53
Show Gist options
  • Save earthling-shruti/4951426 to your computer and use it in GitHub Desktop.
Save earthling-shruti/4951426 to your computer and use it in GitHub Desktop.
import csv
import math
#read csv file
str = []
with open ('scores.csv', 'rb') as csvfile:
file = csv.reader(csvfile, delimiter= ',')
for row in file:
str.append(' '.join(row))
#store schools and scores in different arrays
#needs better way to check schools
#TODO: set variable num_of_schools for future reference
i=1
schools = []
scores = []
for row in str:
if i == 1:
schools.append(row)
else:
scores.append(row)
if i < 6:
i += 1
else:
i = 1
#uncomment next two lines to print schools
#print "schools:",
#print [school for school in schools]
#not sure this is needed, revise
calculate = []
k = i = j = 0
for i in range(14):
calculate.append([])
for j in range(5):
calculate[i].append(scores[k])
k += 1
num = []
sum_array = []
i = 0
for i in range(14):
num.append([])
for j in range(5):
num[i].append(calculate[i][j].split())
winner = winner_score = 0
final = []
max_score = 0.0
min_score = 10.0
for i in range(14):
sum_array = []
for k in range(9):
sum1 = 0.0
for j in range(5):
if num[i][j][k] > max_score:
max_score = float(num[i][j][k])
if num[i][j][k] < min_score:
min_score = float(num[i][j][k])
sum1 = sum1 + float(num[i][j][k])
sum1 = sum1 - min_score - max_score
sum_array.append(round(sum1,2))
final.append(math.fsum(sum_array))
if final[i] > winner_score:
winner = i
winner_score = final[i]
#uncomment next two lines for final scores
#for i in final:
# print i
print "winner:" + schools[winner]
print "winner score:",
print winner_score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment