Skip to content

rehan363/shopping_cart_python

Repository files navigation

Shopping Cart System

A versatile and user-friendly shopping cart implementation in Python, enabling easy management of items in a virtual shopping cart with features like adding/removing items, applying discounts, and saving/loading cart data.

Features

  • Item Management: Add and remove items from your shopping cart
  • Item Categories: Support for different item types (Books, Watches, etc.)
  • Dynamic Discounts: Apply percentage-based or fixed amount discounts
  • Cart Operations: View, clear, save, and load shopping carts
  • Checkout Process: Complete purchases with receipt generation
  • User-Friendly Interface: Interactive command-line interface with clear prompts

Installation

  1. Clone this repository:

    git clone https://github.com/rehan363/shopping_cart_project.git
    cd shopping_cart_project
    
  2. No external dependencies are required - the project uses only Python's standard library.

Usage

Run the main script:

python main.py

Follow the interactive menu to:

  1. Add items to your cart (books, watches)
  2. Remove items from the cart
  3. Apply percentage or fixed amount discounts
  4. View items in your cart with total price
  5. Save/load your cart to/from a JSON file
  6. Clear your cart
  7. Checkout and generate receipts

Project Structure

  • main.py: Entry point of the application with the user interface
  • cart.py: Contains the Cart class for managing shopping cart operations
  • items.py: Defines the Items base class and specialized item types (Books, Watches)
  • discounts.py: Implements discount strategies (Percentage, Fixed)

Class Descriptions

Cart Class

The Cart class manages the collection of items and provides methods for cart operations.

Items Classes

  • Items: Base class for all item types
  • Books: Specialized class for book items with author information
  • Watches: Specialized class for watch items with brand and model attributes

Discount Classes

  • PercentageDiscount: Calculates discounts based on a percentage
  • FixedDiscount: Applies a fixed amount discount to the total

Data Persistence

Cart data can be saved to and loaded from JSON files, allowing users to:

  • Save their shopping cart for later use
  • Load previously saved carts
  • Generate receipts after checkout

Example Usage

# Create a new cart
cart = Cart()

# Add some items
book = Books(name="Python Programming", price=29.99, author="John Smith")
watch = Watches(name="Elegant Watch", price=199.99, brand="Timex", model="Explorer")
cart.add_item(book)
cart.add_item(watch)

# Apply a discount
discount = PercentageDiscount(15)  # 15% discount
new_total = cart.apply_discount(discount)
print(f"Total after discount: ${new_total}")

# Save the cart
save_cart(cart, "my_cart.json")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages