Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Table:
- def __init__(self, name, price):
- self.name = name
- self.price = price
- class TV:
- def __init__(self, name, price):
- self.name = name
- self.price = price
- class Notebook:
- def __init__(self, name, price):
- self.name = name
- self.price = price
- class Cup:
- def __init__(self, name, price):
- self.name = name
- self.price = price
- class Cart:
- def __init__(self):
- self.goods = []
- def add(self, gd):
- self.goods.append(gd)
- def remove(self, indx):
- self.goods.pop(indx)
- def get_list(self):
- result = []
- for item in self.goods:
- result.append(f'{item.name}: {item.price}')
- return result
- cart = Cart()
- # add TVs, Table, Notebooks, and Cup to the cart
- tv1 = TV('TV1', 500)
- tv2 = TV('TV2', 600)
- table = Table('Table1', 200)
- nb1 = Notebook('Notebook1', 1000)
- nb2 = Notebook('Notebook2', 1100)
- cup = Cup('Cup1', 10)
- cart.add(tv1)
- cart.add(tv2)
- cart.add(table)
- cart.add(nb1)
- cart.add(nb2)
- cart.add(cup)
- goods_list = cart.get_list()
- print(goods_list)
- cart.remove(2)
- goods_list = cart.get_list()
- print(goods_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement