Menu

[Solved]Python Code Product Classpy Develop Class Called Product Initialized Using Following Value Q37034818

PYTHON CODE (product class.py): Develop a class called ‘Product’that is initialized using the following values: ‘id’, ‘price’,‘inventory’, and ‘condition’. During the initialization, the valuefor ‘condition’ should be checked and if it is anything other than“New”, “Used”, or “Refurbished”, the constructor should raise a‘ValueError’. The class should have two main methods; ‘sell’ and‘stock’. Both methods accept one argument, which is the quantity.The ‘sell’ method is called whenever a specific quantity of theproduct is sold. It has to update the inventory and print the newinventory on the screen. If the sold quantity is greater than theinventory, a ‘ValueError’ should be raised. The ‘stock’ function iscalled whenever a specific quantity of the product is added to theinventory. This method has to update the inventory and also printthe new inventory on the screen. For example, if you create aproduct called ‘product a’ with the initial inventory of 5, callingfollowing methods should result in the following messages.product_a = Product(123, 45.88, 5, ’New’) product_a.sell(3) #Available inventory: 2 product_a.stock(1) # Available inventory: 3product_a.sell(3) # Available inventory: 0 product_a.sell(1) #ValueError: Ordered quantity cannot be greater than inventory Next,develop two methods to start and end a sale on the product. The‘start sale’ method should accepts one argument, which is thepercentage off the price. Then, it should update the price andprint the new price. The ‘end sale’ method should revert the priceback to the original price and print the updated price. If ‘startsale’ is called while a sale is already going on, it should print amessage that a sale is already going on and ignore the pricechange. A sample scenario is included below.product_a.start_sale(0.5) # Price changed to -> $22.94product_a.end_sale() # Price changed to -> $45.88product_a.start_sale(0.25) # Price changed to -> $34.41product_a.start_sale(0.5) # A sale is already going on, cannotchange the price product_a.end_sale() # Price changed to ->$45.88

Expert Answer


Answer to PYTHON CODE (product class.py): Develop a class called ‘Product’ that is initialized using the following values: ‘… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *