Python Class

0

Witam, mam pewien problem, a więc:
W Classie stworzylem metode add, ktora dodaje do siebie skladniki drinka.
Jednakze nie mam pojecia co zrobic by utworzony zestaw skladnikow stal sie nowym obiektem tej klasy
I moglbym sie do niego odwoływać
Dodaje screenshota

0

class Drink():
def init(self,name,percent,price,capacity):
self.name = name
self.percent = percent
self.price = price
self.capacity = capacity

def __add__(self,other):
    nowydrink = Drink(('{} z {}'.format(self.name,other.name)),(self.price+other.price),(self.capacity+other.capacity),(((self.capacity*self.percent)+  (other.capacity*other.percent))/(self.capacity+other.capacity))
    return nowydrink
    
def __mul__(self,x):
    t = (self.name,self.percent,self.price*x,self.capacity*x)
    return t

drink1=Drink('wódka', 40, 8, 50)
drink2=Drink('rum', 60, 9, 50)
drink3=Drink('cola', 0, 2, 100)
drink4=Drink('lód', 0, 0, 30)
nowydrink = drink1 + drink2

print(drink3.name)
print(nowydrink.mul(3))

0

No to, pomijając już wszelkie uwagi stylistyczne, brakuje Tobie jednego zamykającego nawiasu.

1 użytkowników online, w tym zalogowanych: 0, gości: 1