You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.1 It should have private attributes __name, __price, and __stock_quantity.
6
+
1.2 It should have properties name, price, and stock_quantity to get and set the values of these attributes.
7
+
1.3 The price property should ensure that the price is not negative.
8
+
1.4 The stock_quantity property should ensure that the stock quantity is not negative.
9
+
10
+
2. Create a Class VirtualCart:
11
+
2.1 It should have a private attribute __products which is a dictionary where the key is the product name and the value is an instance of Product.
12
+
2.2 It should have a method add_product(product, quantity) that adds a product to the cart.
13
+
- If the requested quantity exceeds the stock quantity, it should raise a custom exception InsufficientStockError.
14
+
2.3 It should have a method remove_product(product_name) that removes a product from the cart.
15
+
2.4 It should have a method calculate_total() that calculates and returns the total cost of the products in the cart.
16
+
2.5 It should have a method show_cart() that prints the products in the cart with their quantities and prices.
17
+
18
+
3. Testing and Verification:
19
+
3.1 Create several products, add them to the cart, handle exceptions if you try to add more than what is in stock, calculate the total of the cart, and remove a product."""
0 commit comments