Page 243 -
P. 243

smarter pos






                               These are the two discount modules:    starbuzz.py
                      promotion.py
                                                  # Official Starbuzz Discount Module
                                                  # Copyright(c) Starbuzz Corporation
                 def discount(price):
                                                  # All Rights Reserved.
                     return 0.9 * price
                                                  # This function calculates a 5% discount on a price
                                                  def discount(price):
                                                      return 0.95 * price


               Write a new version of coffee_pos.py that, after choosing a menu option, will ask if the
               customer has a Starbuzz Discount Card. If the answer is “Y”, apply both the Starbuzz and the
               promotion discount. Otherwise, just apply the promotion discount.

               Here is the latest version of coffee_pos.py

                          from transactions import *
                          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
                              else:
                                  credit_card = input("Credit card number: ")
                                  new_price = discount(prices[choice - 1])
                                  save_transaction(new_price, credit_card, items[choice - 1])




           208    Chapter 6
   238   239   240   241   242   243   244   245   246   247   248