Question: # Global data products = [ { id : 1 , name: Laptop, price: 1 4 9 9 } , { id
# Global data products id: "name": "Laptop", "price": id: "name": "Smartphone", "price": id: "name": "Headphones", "price": cart # Functions def displayproducts: printAvailable Products:" for product in products: printfproductidproductname $productprice def addtocartproductid: product nextp for p in products if pid productid None if product: cart.appendproduct printfproductname added to cart." else: printProduct not found." def displaycart: printShopping Cart:" for item in cart: printfitemname $itemprice def calculatetotal: total sumitemprice for item in cart printfTotal: $total # Main program while True: print
Display Products
Add to Cart
Display Cart
Calculate Total
Exit" choice inputEnter your choice: if choice : displayproducts elif choice : productid intinputEnter the product ID to add to cart: addtocartproductid elif choice : displaycart elif choice : calculatetotal elif choice : printThank you for shopping. Goodbye!" break else: printInvalid choice. Please try again." Change this code into object oriented approach
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
