Grocery-Store-Billing-System-Python-

๐Ÿ›’ Grocery Billing System (Python)

๐Ÿ“˜ Overview

This is a simple Python-based Grocery Billing System that allows users to:

A great beginner-friendly Python project to understand loops, dictionaries, user input, and basic logic.


๐Ÿง  Features

โœ… Display available stock with item prices
โœ… Add multiple items and quantities to your cart
โœ… Automatic calculation of total cost
โœ… Simple text-based interface for easy use
โœ… Dynamic dictionary-based product management


๐Ÿงฉ Code

groceries = {          
    "bananas": 87,   
    "bread": 219,    
    "milk": 113,     
    "eggs": 351,     
    "cheese": 396,  
    "chicken": 528,   
    "rice": 193,     
    "pasta": 157,     
    "tomatoes": 202,
    "apple": 100
}

def billing():
    print("\n===== Welcome to XYZ store =====\n")
    print("\t==== Stock is here ====")
    
    items = list(groceries.keys())
    cart = {}   # to store what user buys
    
    for i, key in enumerate(items, start=1):
        print(f"\t {i}. {key} : {groceries[key]}")
        
    while True:
        user = int(input(f"\nWhich item do you want to buy (enter number): "))
        if 1 <= user <= len(items):
            chosen_item = items[user - 1]  
            price = groceries[chosen_item]
            qty = int(input(f"Enter quantity of {chosen_item}: "))
            
            # add to cart
            if chosen_item in cart:
                cart[chosen_item] += qty
            else:
                cart[chosen_item] = qty
                
            print(f"\nโœ” Added {qty} {chosen_item}(s) - {price*qty} total")
        else:
            print("\nโŒ Invalid choice, please try again.")
        
        choice = input("\nDo you want to quit? (press 'q' to quit, Enter to continue): ")
        if choice.lower() == 'q':
            print("\n===== Final Bill =====")
            total = 0
            for item, qty in cart.items():
                price = groceries[item]
                cost = price * qty
                total += cost
                print(f"{item} x {qty} = {cost}")
            print("----------------------")
            print(f"Grand Total = {total}")
            print("Thank you for shopping with us! ๐Ÿ›’")
            break

billing()

โš™๏ธ How to Run

  1. Save the file as billing.py
  2. Open a terminal and run:
    python billing.py
    
  3. Follow on-screen prompts to:
    • Select grocery items
    • Enter quantity
    • Quit (q) to see your total bill

๐Ÿงพ Example Output

===== Welcome to XYZ store =====

==== Stock is here ====
 1. bananas : 87
 2. bread : 219
 3. milk : 113
 ...

Which item do you want to buy (enter number): 2
Enter quantity of bread: 3
โœ” Added 3 bread(s) - 657 total

Do you want to quit? (press 'q' to quit, Enter to continue): q

===== Final Bill =====
bread x 3 = 657
----------------------
Grand Total = 657
Thank you for shopping with us! ๐Ÿ›’

๐Ÿ’ก Future Enhancements