Page 240 -
P. 240

modular programming


          The Starbuzz code


           The attachment from Starbuzz was a file called starbuzz.py.
           When you open it, you see this:

      Lines that start with     # Official Starbuzz Discount Module
      # are comments; Python    # Copyright(c) Starbuzz Corporation
      will ignore them.
                                # All Rights Reserved.
                                # This function calculates a 5% discount on a price
            This is the         def discount(price):
             discount function,       return 0.95 * price
             as provided by
             Starbuzz.



                                                                        This function returns a price
           The first few lines begin with # characters; these are comments.   that's 5% lower than the price it
           Comments are just notes added by a programmer that are intended   was given.
           to be read by other programmers. Python will ignore them, because
           comments are not code.
          After the comments comes the Starbuzz discount() function. It’s
           just like the discount function you wrote, except instead of returning a
          10% discount, it returns a 5% discount.
          Your code will have to use both discounts:



                               It will apply a 10% discount to everything.


                               And if somebody presents a Starbuzz Discount Card, it will also have to
                             apply the 5% Starbuzz discount.








                           You need to change the code so that it uses both of the discount()
                           functions. Can you see a problem? What is it?







                                                                                      you are here 4    205
   235   236   237   238   239   240   241   242   243   244   245