Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Drink:
- def __init__(self, name, price, percent, capacity):
- self.name = name
- self.price = price
- self.percent = percent
- self.capacity = capacity
- def __add__(self, inny):
- name = self.name + " z " + inny.name
- price = self.price + inny.price
- obj = self.capacity + inny.capacity
- procent = (self.percent * self.capacity + inny.capacity * inny.percent) / (self.capacity + inny.capacity)
- wynik = Drink(name,price,obj,procent)
- return wynik
- def __mul__(self, number):
- price = self.price * number
- obj = self.capacity * number
- return Drink(self.name, price, self.percent, obj)
- def __str__(self):
- return self.name + ", " + str(self.percent) + "%, " + str(self.price) + "zl, " + str(self.capacity) + "ml;"
- __repr__ = __str__
- def __lt__(self, inny):
- return (self.price/self.percent) < (inny.price/inny.percent)
- wodka = Drink("wodka", 5, 40.0, 40)
- martini = Drink("martini", 10, 11.0, 25)
- sprite = Drink("sprite", 4, 0.0, 200)
- lod = Drink("lod", 0, 0.0, 50)
- drink1 = wodka + martini + sprite + lod
- drink2 = wodka + sprite + lod
- drink3 = martini + lod
- print(drink2)
- print(drink3*3)
- lista = [drink1, drink2, drink3]
- lista.sort()
- print(lista)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement