Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # --- 10 allegro
  2.  
  3. class Product:
  4. def __init__(self, name, price):
  5. self.name = name
  6. self.price = price
  7.  
  8. def __str__(self):
  9. return f'class Product, name: {self.name}, price: {self.price}'
  10.  
  11.  
  12. laptop = Product('apple', 4300)
  13. watch = Product('watch', 2400)
  14.  
  15. print(laptop)
  16. print(laptop.name)
  17.  
  18.  
  19. class Basket:
  20. def __init__(self, name, price, quantity):
  21. self.name = name
  22. self.price = price
  23. self.quantity = quantity
  24.  
  25. products = {f'{self.name}': [self.quantity, self.price]}
  26.  
  27. def add_new_product(self):
  28. pass
  29.  
  30. def delete_product(self):
  31. del products[f'{self.name}']
  32.  
  33. def remove_all(self):
  34. if input('remove all? y/n\n') == y:
  35. products = {}
  36. else:
  37. pass
  38.  
  39. def basket_value(self):
  40. return sum(products.vaues[1])
  41.  
  42. def __str__(self):
  43. return f'you have: {products.keys()} worth of {self.basket_value()}'
  44.  
  45.  
  46. adams_basket = Basket(laptop.name, laptop.price, 2)
  47. adams_basket.add_new_product(watch.name, watch.price, 2)
  48.  
  49.  
  50. print(adams_basket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement