Question: Create a class called Item. Item will have 3 attributes: price ( a float containing the value of the item ) , qunatity ( a
Create a class called Item. Item will have attributes: price a float containing the value of the
item qunatity a nonnegative integer specifying how many of that item are present and
descriptiona string that will describe what the item is
Create a class called Cart. Cart will have attributes: basket a list of Items that are currently in
the cart and total a float that represents the total price of all items in the cart combined
Write a function addtocart that takes a Cart object and an Item object and adds the Item to the Cart.
For instance add kiwis to my cart This function should be aware if the Item decription is already
present in the cart then just increase the quantity of the Item in the cart by the Quantity of the
passed Item.
Write a function removefromcart that takes a Car object, an Item.description and an amount. If the item
is present in the cart remove that many of said Item. If the amount is bigger than the quanitity of
that item in the cart then jsut remove all quantity of that item, do not have a negative quantity. If
The item does not exist in the carat tell the user that that item does not exist in the cart.
Write a funciton printcart that uses fstrings to print out the contents of the cart.basket. There should
be three columns printed: Description, Quntity, Price. Center the columns and subsequent rows within
blank spaces each. For each item display the descirption, quantity, and pricequantity in line
with the columns. After the table, output a the total price of all Items in the cart.
Create an instance of the Class cart and add the following items to it in this order:
Apple for $ each
Milk for $
Dozen Eggs for $
lb Bacon for $ each
Apple for $ each
Remove one lb Bacon from the Cart.
Display the contents of the cart using printcart
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
