Page 237 -
P. 237

discount applied




                                            You needed to change the coffee bar POS program to apply the 10%
                                             discount to everything that’s sold. You had three tasks.



              1    Start by creating a new module called promotion.py containing
                   one function:
                                                    Multiplying the price by 0.9
                       def discount(price):
                              return 0.9 * price    will give you a 10% discount..




              2    Complete the code in the above function so that it returns 90% of the price it is
                   given.


              3    This is the latest version of the coffee_pos.py module. Modify it so that it
                   uses the new module to cut the price of everything that’s sold.

                                                   You need to import the code
               from transactions import *          from the “promotion.py” module.
               from promotion import *

               items   = ["DONUT", "LATTE", "FILTER", "MUFFIN"]
               prices  = [1.50, 2.20, 1.80, 1.20]
               running = True


               while running:
                   option = 1
                   for choice in items:
                       print(str(option) + ". " + choice)
                       option = option + 1
                   print(str(option) + ". Quit")
                   choice = int(input("Choose an option: "))
                   if choice == option:
                       running = False
                                                                                 Your code should
                                                                                 call the “discount()”
                   else:
                       credit_card = input("Credit card number: ")               function.
                         new_price=discount(prices[choice - 1])

                       save_transaction(prices[choice - 1], credit_card, items[choice - 1])
                                                   new_price     “new_price” is the discounted value of the price.



           202    Chapter 6
   232   233   234   235   236   237   238   239   240   241   242