0

(Python core) Module Project Juice Maker

I don't know how to solve it

30th Mar 2021, 8:46 AM
Hairul Danial
Hairul Danial - avatar
6 ответов
+ 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)
30th Mar 2021, 9:10 AM
A͢J
A͢J - avatar
+ 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)
30th Mar 2021, 9:00 AM
Hairul Danial
Hairul Danial - avatar
+ 2
Try first And show your try here !
30th Mar 2021, 8:51 AM
Ayush Kumar
Ayush Kumar - avatar
+ 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)
29th Jun 2021, 7:01 AM
Rushil Purohit
Rushil Purohit - avatar
+ 1
Thanks guys
30th Mar 2021, 10:39 AM
Hairul Danial
Hairul Danial - avatar
+ 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)
19th Apr 2021, 12:05 PM
Mailan Savelino Caberios
Mailan Savelino Caberios - avatar