Page 159 -
P. 159

find the top score








                               Here is the current version of the program:



                                           highest_score = 0
                                           result_f = open("results.txt")
                                           for line in result_f:
                                               if float(line) > highest_score:
                                                   highest_score = float(line)
                                           result_f.close()
                                           print("The highest score was:")
                                           print(highest_score)


               You were to write the extra code required to take advantage of the split() method and
               multiple assignment in order to create variables called name and score, then use them to
               complete the program to find the highest score.






                                                                 Add in the call to the split() method
                                                                 to cut the line in two, creating the
                                                                 “name" and “score" variables.
                 The only code changes    for line in result_f:
                 required are within the
                 for loop. The rest of          (name, score) = line.split()
                 the program remains
                 unchanged.                     if float(score) > highest_score:

                                                      highest_score = float(score)

                                             You are no longer
                                             comparing the line to
                                             the highest score, so
                                             be sure to compare the
                                            “score" variable instead.










           124    Chapter 4
   154   155   156   157   158   159   160   161   162   163   164