Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # --- 10 allegro
- class Product:
- def __init__(self, name, price):
- self.name = name
- self.price = price
- def __str__(self):
- return f'class Product, name: {self.name}, price: {self.price}'
- laptop = Product('apple', 4300)
- watch = Product('watch', 2400)
- print(laptop)
- print(laptop.name)
- class Basket:
- def __init__(self, name, price, quantity):
- self.name = name
- self.price = price
- self.quantity = quantity
- products = {f'{self.name}': [self.quantity, self.price]}
- def add_new_product(self):
- pass
- def delete_product(self):
- del products[f'{self.name}']
- def remove_all(self):
- if input('remove all? y/n\n') == y:
- products = {}
- else:
- pass
- def basket_value(self):
- return sum(products.vaues[1])
- def __str__(self):
- return f'you have: {products.keys()} worth of {self.basket_value()}'
- adams_basket = Basket(laptop.name, laptop.price, 2)
- adams_basket.add_new_product(watch.name, watch.price, 2)
- print(adams_basket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement