One of the key features of any e-commerce website is the shopping basket. It is used to let the end-users add products to their basket before proceeding to checkout.
In this Python challenge we will create a Shopping Basket class to implement the different functionalities (behaviours) such as:
-
Adding an item to the shopping basket,
Removing an item from the shopping basket,
Updating the desired quantity of an item from the shopping basket,
Viewing/listing the content of the shopping basket,
Calculating the total cost of the shopping basket,
Emptying/Resetting the shopping basket,
Checking if the shopping basket is empty.
To do so we will create the following two classes:
The items property of the Shopping Basket class will be a dictionary of items:quantity pairs. (The items are the keys, for each key, the quantity in the basket is the value)
Python Code
Your task
Add a new “Stock Level” property to the item class.
Update the addItem(), removeItem(), updateItem() and reset() methods of the Shopping Basket class to check the availability of the item in stock before adding/changing the desired quantity, and by updating the Stock Level property of the item class accordingly when items are added/removed from the shopping basket.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area