Tqst DRIVQ

With the results . txt file saved to the same directory as your program, enter this code into IDLE and see what happens. Remember to save your program, then press F5 to run it.

Those results look a little strange. Zack is only a novice surfer but, according to the results from your program, Zack has the highest score. It looks like the association between the surfer names and their scores is somehow lost... and if you think about it, this is exactly what's happening.

The two arrays are independent of each other: one contains scores, the other names. When the data is in the file, the surfer name and the scores are associated with each other because they appear on the same line. However, once the split occurs and the data is in the arrays, the association is severed. Sorting one array has no effect on the ordering of the other. No wonder your results are a little off the wall.

How do you fix this?

need a new data structure

Was this article helpful?

0 0

Post a comment