Question: Write a Python code. Write a class called ShoppingCart that might be used in an online store. It should have the following: A list of

Write a Python code.

Write a class called ShoppingCart that might be used in an online store. It should have the following:

A list of Item objects that represents the items in the shopping cart.

A constructor that creates an empty list of items (the constructor should take no arguments except self).

A method called add() that takes a name and a price and adds an Item object with that name and price to the shopping cart.

A method called total() that takes no arguments and returns the total cost of the items in the cart.

A method called remove_items() that takes an item name (a string) and removes any Item objects with that name from the shopping cart. It shouldnt return anything.

A __str__() method that returns a string containing info on all the items in the shopping cart.

Then test out the shopping cart as follows:

(1) create a shopping cart called mycart.

(2) add several items to it;

(3) print the carts total cost (using the total() method);

(4) remove one of the items types;

(5) print out the cart.

Please answer the question AS SOON AS POSSIBLE and I will give thumbs up and a good comment.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!