Page 245 -
P. 245

getting a promotion






                               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


                You were asked to write a new version of coffee_pos.py that, after choosing an 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])




           210    Chapter 6
   240   241   242   243   244   245   246   247   248   249   250