ASSIGNMENT
Q.11
Q.11 Write a menu-driven Python program to create a Shopping Cart program that allows the user to:
Add products.
Remove products.
Search a product.
Display all products.
Sort products alphabetically.
Reverse the product list.
Count total products.
cart = [] while True: print("\n===== SHOPPING CART MENU =====") print("1. Add Product") print("2. Remove Product") print("3. Search Product") print("4. Display All Products") print("5. Sort Products Alphabetically") print("6. Reverse Product List") print("7. Count Total Products") print("8. Exit") choice = int(input("Enter your choice: ")) if choice == 1: product = input("Enter product name: ") cart.append(product) print("Product added successfully.") elif choice == 2: product = input("Enter product name to remove: ") if product in cart: cart.remove(product) print("Product removed successfully.") else: print("Product not found.") elif choice == 3: product = input("Enter product name to search: ") if product in cart: print("Product found at position", cart.index(product) + 1) else: print("Product not found.") elif choice == 4: if len(cart) == 0: print("Shopping cart is empty.") else: print("Products in Shopping Cart:") for i in range(len(cart)): print(i + 1, ".", cart[i]) elif choice == 5: cart.sort() print("Products sorted alphabetically.") elif choice == 6: cart.reverse() print("Product list reversed.") elif choice == 7: print("Total Products:", len(cart)) elif choice == 8: print("Thank you for shopping!") break else: print("Invalid Choice! Please try again.")


