0
(Python core) Module Project Juice Maker
I don't know how to solve it
6 Respuestas
+ 4
Hairul Danial
Remove input (self)(name)
And add this function before the __str__ function
def __add__(self, obj):
name = self.name + "&" + obj.name
cap = self.capacity + obj.capacity
return Juice(name, cap)
+ 3
class Juice:
def __init__(self, name, capacity):
self.name = name
self.capacity = capacity
input(self)(name )
def __str__(self):
return (self.name + ' ('+str(self.capacity)+'L)')
a = Juice('Orange', 1.5)
b = Juice('Apple', 2.0)
result = a + b
print(result)
+ 2
Try first
And show your try here !
+ 2
class Juice:
def __init__(self, name, capacity):
self.name = name
self.capacity = capacity
def __str__(self):
return (self.name + ' ('+str(self.capacity)+'L)')
def __add__(self, other):
return Juice(self.name + '&' + other.name,self.capacity+other.capacity)
a = Juice('Orange', 1.5)
b = Juice('Apple', 2.0)
result = a + b
print(result)
+ 1
Thanks guys
+ 1
class Juice:
def __init__(self, name, capacity):
self.name = name
self.capacity = capacity
def __str__(self):
return (self.name + ' ('+str(self.capacity)+'L)')
def __add__(self, other):
return Juice(self.name + '&' + other.name,self.capacity+other.capacity)
a = Juice('Orange', 1.5)
b = Juice('Apple', 2.0)
result = a + b
print(result)