Page 235 -
P. 235

custom data objects




                              Let’s add two methods to your class. The first, called add_time(), appends a single
                              additional timing value to an athlete’s timing data. The second, add_times(), extends an
                              athlete’s timing data with one or more timing values supplied as a list.
                              Here’s your current class: add the code to implement these two new methods.

                              class Athlete:
                                  def __init__(self, a_name, a_dob=None, a_times=[]):
                                      self.name = a_name
                                      self.dob = a_dob
                                      self.times = a_times

                                  def top3(self):
                                      return(sorted(set([sanitize(t) for t in self.times]))[0:3])
             Add your new
              methods here.
























                                                Don’t put down the pencil just yet! Provide a few lines of code to
                                                test your new functionality:
















                                                                                      you are here 4    199
   230   231   232   233   234   235   236   237   238   239   240