Python OOP challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Python OOP challenge

Create a class called ShoppingCart. Create a constructor that takes no arguments and sets the total attribute to zero, and initializes an empty dict attribute named items. Create a method add_item that requires item_name, quantity and price arguments. This method should add the cost of the added items to the current value of total. It should also add an entry to the items dict such that the key is the item_name and the value is the quantity of the item. Create a method remove_item that requires similar arguments as add_item. It should remove items that have been added to the shopping cart and are not required. This method should deduct the cost of the removed items from the current total and also update the items dict accordingly. If the quantity of an item to be removed exceeds the current quantity of that item in the cart, assume that all entries of that item are to be removed. Create a method checkout that takes in cash_paid and returns the value of balance from the payment. If cash_paid is not enough to cover the total, return "Cash paid not enough". Create a class called Shop that has a constructor which takes no arguments and initializes an attribute called quantity at 100. Make sure Shop inherits from ShoppingCart. In the Shop class, override the remove_item method, such that calling Shop's remove_item with no arguments decrements quantity by one.

12th Apr 2017, 12:14 AM
Obongekeme Udo
Obongekeme Udo - avatar
5 Answers
+ 15
It looks more like homework than a challenge. I'll pass
12th Apr 2017, 1:26 AM
Jafca
Jafca - avatar
+ 6
lmao ill admit its a more creative way of getting us to do your homework than this guy https://www.sololearn.com/discuss/310938/?ref=app
12th Apr 2017, 3:43 AM
Edward
+ 5
Fun? I have only read the challenge and I'm already bored xD
12th Apr 2017, 1:42 AM
Abner Schmidt
Abner Schmidt - avatar
0
This is surly an homework not a challenge
23rd Apr 2017, 11:55 AM
Benjamin
Benjamin - avatar
- 2
@Benjamin...lol. You don carry your mumu come here abi?
23rd Apr 2017, 2:29 PM
Obongekeme Udo
Obongekeme Udo - avatar