I'm currently trying to make a scoreboard for a competition from a text file for a uni project.
Each competitor has a competitor_no, competitor_name, and 3 scores they are all displayed on separate lines in the text file (so each competitors data takes 5 lines) eg:
1
Eliza Ianson
9.19
11.79
21.66
2
Cece Durant
17.03
7.02
17.72
I need to be able to add the 3 scores to get the overall score.I have 50 competitors and need to compare them all to display the top 3 competitors printing the competitors number,name and overall score. Is there a way to assign the line value to a variable?
Obviously I am going to need to compare 5 lines at a time to get the required information for each individual competitor and process the data this is how I have code set in my program.
file = open('veggies_2014.dat')
for line in file:
first_place = []
second_place = []
third_place = []
a = 1
b = 2
c = 3
d = 4
e = 5
if line == a:
competitor_no = line
elif line == b:
competitor_name = line
elif line == c:
cucumber = line
elif line == d:
carrot = line
elif line == e:
runner_bean = line
a += 5
b += 5
c += 5
d += 5
e += 5
score = float(cucumber) + float(carrot) + float(runner_bean)
print(score)
if score > first:
first = score
first_place.append(competitor_no)
first_place.append(competitor_name)
first_place.append(score)
elif score > second:
second = score
second_place.append(competitor_no)
second_place.append(competitor_name)
second_place.append(score)
elif score > third:
third = score
third_place.append(competitor_no)
third_place.append(competitor_name)
third_place.append(score)
file.close()
print (first_place)
print (second_place)
print (third_place)
I can get the score if statement to work when I am just dealing with a file containing numbers, but having to include the name is where I seem to be stumbling.
Any suggestions?