Question: Question 5a. Create a class that satisfies the following specifications. Class name Backpack Class attribute style: str Instance attributes account id: str inventory: dict Parameters

 Question 5a. Create a class that satisfies the following specifications. Classname Backpack Class attribute style: str Instance attributes account id: str inventory:dict Parameters account id: str Detailed information Assign the str "basic" tothe class attribute, style. The value of the instance attribute, account id,should be assigned with the argument of the same name in the

Question 5a. Create a class that satisfies the following specifications. Class name Backpack Class attribute style: str Instance attributes account id: str inventory: dict Parameters account id: str Detailed information Assign the str "basic" to the class attribute, style. The value of the instance attribute, account id, should be assigned with the argument of the same name in the constructor. The instance attribute, inventory, is an empty dictionary when a Backpack object is instantiated. The keys in the dictionary are the items' names, of str type, while the values, of int type, mark the quantity of the items in the cart.Question 5') 1Write an instance method for the BackPaok class that satises the followin + s . - oioations. Detailed description l. item_name: str 2. quantity: int The metion should check if the item exists in the keys of the instance attribute, inventory, and update the number of the items in the inventoryr accordingly. That is. if the item does not exist in the inventory, it should create a keyvalue pair for the inventory. Otherwise. it should add the quantity in the argument to the existing Vl. You may assume that the quantity in the arglu'nent will be more than t]. Question 5c Write an instance method for the ShoppingCart class that satisfies the following specifications. Method name remove item from bag Parameter 1. item name: str 2 . quantity: int Return value Detailed description The function should update the inventory attribute with the correct number of items. If the updated quantity is 0, the key value pair should be removed from the inventory. You can assume that the item name in the argument is in the inventory and the quantity to be removed is less than or equal to the quantity in the inventory.Question 5:] Write an instance method for the Baal-{Pack class that satisfies the foltowin s -- ifications. _ _ Detailed description This method empties the instance attribute inventory Question 5! Write an instance method for the Havel-{Pack class that satises the foliowin s . -oications. _ Detailed description This method returns the total number of items based on the existing items in the inventory. If there is nothing in the inventory; the return value should he . An example of how your code should work given the following parameters. bag = BackPack("394eds7A" ) bag . add_item_to_bag("dagger", 1) bag . add_item_to_bag("wooden sword", 2) bag. add_item_to_bag ("red potion", 3) bag . add_item_to_bag ("red potion", 2) # bag. inventory is now {"dagger": 1, "wooden sword": 2, "red potion": 5} bag . remove_item_from_bag ( "wooden sword", 1) bag . remove_item_from_bag("red potion", 5) # bag. inventory is now {"dagger": 1, "wooden sword": 1} bag . count_items ( ) # returns 2 bag . empty_bag ( ) bag . count_items ( ) # returns 0

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 Programming Questions!