Question: 2. Python: Shopping Cart The task is to implement two classes: Shopping Cart and Item according to the following requirements: Item - An item is

2. Python: Shopping Cart The task is to implement two classes: Shopping Cart and Item according to the following requirements: Item - An item is instantiated using the constructor Item(name: str, price: int) where the name denotes the name of the item, and the price denotes the price of the item. - Its name can be retrieved as a normal attribute, that is, if item is an instance of Item, then item.name returns the name of the item. Shopping Cart - A shopping cart is instantiated using a constructor without arguments, i.e. Shopping Cart() - It has a method add(item: Item) that adds the given item to the cart. An item may be added to the cart multiple times. An item will be added each time the add method is called. - It has a method, total)-> int that returns the sum of the prices of all items currently in the cart. - Calling len(cart) where the cart is an instance of a ShoppingCart returns the number of items in the cart. Implementations of the classes will be tested by a provided code stub and several input files that contain parameters. First, the stub initializes instances of Items an instance of the Shopping Cart. Next, it performs the given operations on the Shopping Cart instance. The result of their executions will be printed to the standard output by the provided code. Constraints There will be at most 5 different items. There will be at most 500 operations to perform on the cart.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the ShoppingCart and Item classes in Python according to the requirements specified in ... View full answer

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!