Keeping track of scores makes the code more complex

So how will you keep track of the extra scores? You could do something like this.

This is HOT veal Python ¿ode. it's what -programme« ¿all "pseudoCode." They use it when they ave sketching out ideas and wovking out a program's logic.

set the highest_score to 0 set the second_highest to 0 set the third_highest to 0 iterate through each of the scores: if the score > highest_score:

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

I | If the scores came before the names in the file Q^] If you knew exactly how many lines are in the file sort the data

You were think about what would make the program easier to write and check the box that you think would have the greatest impact:

| | If there were no names in the file, only numbers Qj If the data were ordered highest to lowest I | If the scores came before the names in the file Q^] If you knew exactly how many lines are in the file

Was this article helpful?

0 0

Post a comment