🏠 Home 📚 Chapters 💻 Projects ℹ️ About
HomeProjects › Day 30
DAY 30 — 60 DAY PYTHON CHALLENGE

💻 Shopping Cart

Python में Shopping Cart — खरीदारी टोकरी

Advertisement

Project kya hai?

Day 30 ka project hai Shopping Cart! Neeche complete code hai — copy karo aur chalao!

Complete Python Code

python — cart.py
products = {
    "Apple":    {"price": 50,  "stock": 100},
    "Banana":   {"price": 30,  "stock": 150},
    "Milk":     {"price": 60,  "stock": 50},
    "Bread":    {"price": 40,  "stock": 80},
    "Rice":     {"price": 120, "stock": 30},
    "Dal":      {"price": 100, "stock": 40},
    "Biscuit":  {"price": 25,  "stock": 200},
    "Shampoo":  {"price": 180, "stock": 25},
}

cart = {}
print("=== Online Shopping Cart ===")

while True:
    print("
1. Products dekho")
    print("2. Cart mein add karo")
    print("3. Cart se remove karo")
    print("4. Cart dekho")
    print("5. Checkout (Bill)")
    print("6. Baahar jao")
    ch = input("Choice: ")
    if ch == "1":
        print(f"
{'Product':12} {'Price':8} {'Stock'}")
        print("-" * 30)
        for name, info in products.items():
            print(f"  {name:10}  Rs{info['price']:6}  {info['stock']} units")
    elif ch == "2":
        name = input("Product naam: ").title()
        if name in products:
            qty = int(input(f"Quantity: "))
            if qty <= products[name]["stock"]:
                cart[name] = cart.get(name, 0) + qty
                products[name]["stock"] -= qty
                print(f"  {qty}x {name} cart mein add hua!")
            else:
                print(f"  Sirf {products[name]['stock']} units available!")
        else:
            print("  Product nahi mila!")
    elif ch == "3":
        name = input("Remove product: ").title()
        if name in cart:
            qty = int(input(f"Kitna remove karein (max {cart[name]}): "))
            qty = min(qty, cart[name])
            cart[name] -= qty
            products[name]["stock"] += qty
            if cart[name] == 0: del cart[name]
            print(f"  {qty}x {name} removed!")
        else:
            print("  Cart mein nahi hai!")
    elif ch == "4":
        if not cart:
            print("Cart khaali hai!")
        else:
            print(f"
{'Product':12} {'Qty':6} {'Price':8} {'Subtotal'}")
            print("-" * 40)
            total = 0
            for name, qty in cart.items():
                sub = products[name]["price"] * qty
                total += sub
                print(f"  {name:10}  {qty:5}  Rs{products[name]['price']:6}  Rs{sub}")
            print(f"
  Total: Rs{total}")
    elif ch == "5":
        if not cart:
            print("Cart khaali hai!")
        else:
            total    = sum(products[n]["price"]*q for n,q in cart.items())
            discount = total * 0.1 if total > 500 else 0
            gst      = (total - discount) * 0.05
            grand    = total - discount + gst
            print(f"
=== BILL ===")
            for name, qty in cart.items():
                print(f"  {name}: {qty} x Rs{products[name]['price']}")
            print(f"
  Subtotal : Rs{total:.0f}")
            if discount: print(f"  Discount : -Rs{discount:.0f} (10% off Rs500+)")
            print(f"  GST (5%) : Rs{gst:.0f}")
            print(f"  Total    : Rs{grand:.0f}")
            cart = {}
            print("
Shukriya! Dobara aaiye!")
    elif ch == "6":
        break
OUTPUT
Choice: 1
Product      Price    Stock
  Apple       Rs50     100 units
  Milk        Rs60     50 units

Choice: 2
Product: Apple
Qty: 3
  3x Apple cart mein add hua!

=== BILL ===
  Apple: 3 x Rs50
  Subtotal: Rs150
  GST: Rs8
  Total: Rs158

Code kaise kaam karta hai?

Products dictionary mein price aur stock track hoti hai. Stock automatically decrease hota hai jab add hota hai. 10% discount Rs500+ par. Real e-commerce jaisa!
Advertisement

📋 Project ka Introduction

Shopping Cart Python ka Day 30 ka project hai. Is project mein aap Python ke important concepts practice karenge jo real-world applications mein bahut use hote hain.

Yeh project beginners ke liye design kiya gaya hai lekin kaafi concepts cover karta hai. Step by step samjho, code chalao, aur khud modify karke practice karo.

Is tarah ke projects banane se aapka Python confidence badh jaata hai aur aap asli problems solve karna seekh jaate hain. Chaliye code samjhte hain!

🧠 Is Project mein kya seekhoge?

Yeh project banate waqt aap ye Python concepts use karoge:
ConceptKya karta hai
VariablesData store karna
FunctionsReusable code blocks
LoopsRepeat karna
ConditionsDecisions lena
Input/OutputUser se interact karna

📝 Code kaise kaam karta hai — Step by Step

Neeche code ki poori logic step-by-step samjhayi gayi hai:
  1. Problem samjho: Shopping Cart mein kya karna hai
  2. Required variables aur data structures decide karo
  3. Logic step-by-step likhó
  4. Code mein implement karo
  5. Test karo aur bugs fix karo

⚠️ Common Mistakes — Bhool mat jaana!

Beginners yeh galtiyan aksar karte hain — dhyan rakho:
  • ⚠️ Indentation sahi rakho — Python mein spaces matter karti hain
  • ⚠️ Variables ko use se pehle define karo
  • ⚠️ Input ko int()/float() mein convert karo agar number chahiye
  • ⚠️ Edge cases handle karo — kya hoga agar user galat input de?

🏋️ Practice Exercises — Aage badho!

Yeh project complete karne ke baad in exercises se practice karo:
  • 💡 Shopping Cart mein naya feature add karo
  • 💡 Code ko functions mein refactor karo
  • 💡 Error handling improve karo
  • 💡 File mein data save karo

❓ Aksar Pooche Jane Wale Sawal (FAQ)

Q: Shopping Cart project kyon banana chahiye?

A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
Q: Code run nahi ho raha?

A: Indentation check karo, syntax errors dekho, variables define hain ya nahi check karo.
Q: Kaise improve karein?

A: Pehle basic version complete karo, phir ek ek feature add karte jao.
🏠 📋 Projects Day 31 →