├── README.md └── cashier.py /README.md: -------------------------------------------------------------------------------- 1 | # supermarket-cashier 2 | Subject 14 - Project One: Supermarket Cashier 3 | -------------------------------------------------------------------------------- /cashier.py: -------------------------------------------------------------------------------- 1 | def enterProducts(): 2 | buyingData = {} 3 | enterDetails = True 4 | while enterDetails: 5 | details = input("Press A to add product and Q to quit: ") 6 | if details == "A": 7 | product = input("Enter product: ") 8 | quantity = int(input("Enter quantity: ")) 9 | buyingData.update({product: quantity}) 10 | elif details == "Q": 11 | enterDetails = False 12 | else: 13 | print("Please select a correct option") 14 | return buyingData 15 | 16 | 17 | def getPrice(product, quantity): 18 | priceData = { 19 | 'Biscuit': 3, 20 | 'Chicken': 5, 21 | 'Egg': 1, 22 | 'Fish': 3, 23 | 'Coke': 2, 24 | 'Bread': 2, 25 | 'Apple': 3, 26 | 'Onion': 3 27 | } 28 | subtotal = priceData[product] * quantity 29 | print(product + ':$' + 30 | str(priceData[product]) + 'x' + str(quantity) + '=' + str(subtotal)) 31 | return subtotal 32 | 33 | 34 | def getDiscount(billAmount, membership): 35 | discount = 0 36 | if billAmount >= 25: 37 | if membership == 'Gold': 38 | billAmount = billAmount * 0.80 39 | discount = 20 40 | elif membership == 'Silver': 41 | billAmount = billAmount*0.90 42 | discount = 10 43 | elif membership == 'Bronze': 44 | billAmount = billAmount*0.95 45 | discount = 5 46 | print(str(discount) + "% off for " + membership + 47 | " " + "membership on total amount: $" + str(billAmount)) 48 | else: 49 | print("No discount on amount less than $25") 50 | return billAmount 51 | 52 | 53 | def makeBill(buyingData, membership): 54 | billAmount = 0 55 | for key, value in buyingData.items(): 56 | billAmount += getPrice(key, value) 57 | billAmount = getDiscount(billAmount, membership) 58 | print("The discounted amount is $" + str(billAmount)) 59 | 60 | 61 | buyingData = enterProducts() 62 | membership = input("Enter customer membership: ") 63 | makeBill(buyingData, membership) 64 | --------------------------------------------------------------------------------