I'm trying to create a program with "Item" and "Shopping Cart" as 2 separate classes.
Using a "Shopping Cart" I should be able to add/remove/update and get the total cost the items listed in "Items" in the cart, but I'm unsure of how to access the "Items" dictionary and add it to the shopping cart list.
l_items = ({"teddy": {'name': 'Teddy',
"desc": "toy",
"price": 3.21},
"sweet": {'name': 'Rolo',
"desc": 'chocolate',
'price': 1.21}})
class Item:
def __init__(self, name, desc, price):
self._name = name
self._desc = desc
self._price = price
self._stock = len(l_items)
def __repr__(self):
return self.name
class ShoppingCart:
def __init__(self, item=[]):
self._item = item
def add_item(self, new):
self._item.append(new)
def remove_item(self, remove):
self._item.remove(remove)
def update_item(self, update):
pass
def view(self):
return self
def getTotalCost(self):
total = 0
for i in self._item:
total += i.getTotalCost()
def reset(self):
self._item = []
def isEmpty(self):
return len(self._items) == 0