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