Page 162 -
P. 162
data in files and arrays
Keeping track of 3 scores makes the code
more complex
So how will you keep track of the extra scores? You could do something
like this:
This is NOT real set the highest_score to 0
Python code. It's what
programmers call “pseudo- set the second_highest to 0
code." They use it when set the third_highest to 0
they are sketching out iterate through each of the scores:
ideas and working out a if the score > highest_score:
program's logic.
set the third_highest to second_highest
set the second_highest to highest_score
set the highest_score to score
otherwise if the score > second_highest:
set the third_highest to second_highest
set the second_highest to score
otherwise if the score > third_highest:
set the third_highest to score
You can see that there’s a lot more logic here, because the program needs
to “think” a bit more. Unfortunately, turning this logic into code will
make the program longer and harder to change in the future. And, let’s be
honest, it’s somewhat more difficult to understand what’s actually going
on with the logic as shown here.
How could you make this simpler?
Think about what would make the program easier to write. Check
the box that you think would have the greatest impact:
If there were no names in the file, only numbers If the data were ordered highest to lowest
If the scores came before the names in the file If you knew exactly how many lines are in the file
you are here 4 127