Page 174 -
P. 174
data in files and arrays
Sort the scores from highest to lowest
You now need to add the two method calls into your code that will sort the
array. The lines need to go between the code that reads the data into the list
and before the code that displays the first three elements:
The array starts off in a random
order. It's “unsorted."
boxes
0 1 2 3
Here is the existing program. Add in the missing code that sorts
the data, highest-to-lowest.
scores = []
result_f = open("results.txt")
for line in result_f:
(name, score) = line.split()
scores.append(float(score))
Put the extra result_f.close()
code here.
print("The top scores were:")
print(scores[0])
print(scores[1])
print(scores[2])
you are here 4 139