Project in Python - Supermarket Cashier

post-image


Let's have a look at how the flow of the project would look like:
flow-chart



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':30,
        'Chicken':200,
        'Egg':10,
        'Fish':300,
        'Coke':50,
        'Bread':20,
        'Apple':100,
        'Onion':80
    }
    subtotal = priceData[product]*quantity
    print(product + '₹' + str(priceData[product] + 'x' + 
        str(quantity) + '=' + str(subtotal)))
    return subtotal

 
def getDiscount(billAmount,membership):
    discount = 0
    if billAmount >= 1000:
        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 ₹1000')
    return billAmount

 
def makeBill(buyingData,membership):
    billAmount = 0
    for keyvalue in buyingData.items():
        billAmount += getPrice(keyvalue)
    billAmount = getDiscount(billAmountmembership)
    print('The discounted amount is ₹' + str(billAmount))


buyingData = enterProducts()
membership = input('Enter customer membership: ')
makeBill(buyingDatamembership)




Output:
Press A to add product and Q to quit: A
Enter product: Bread
Enter quantity: 5
Press A to add product and Q to quit: A
Enter product: Coke
Enter quantity: 7
Press A to add product and Q to quit: A
Enter product: Fish
Enter quantity: 2
Press A to add product and Q to quit: A
Enter product: Egg
Enter quantity: 12
Press A to add product and Q to quit: Q
Enter customer membership: Silver
Bread: ₹20x5=100
Coke: ₹50*7=350
Fish: ₹300*2=600
Egg: ₹10*12=120
10%off for Silver membership on total amount: ₹1170
The discounted amount is ₹1053