- 8

Python 3 Juice maker question

class Juice: def __init__(self, name, capacity): self.name = name self.capacity = capacity def __add__(self,obj): name=self.name+"&"+obj.name cap=self.capacity+obj.capacity return Juice(name,cap) 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)

3rd Feb 2021, 6:59 PM
Biswajit Sahu
Biswajit Sahu - avatar
8 Antworten
+ 3
What's your question?
3rd Feb 2021, 7:11 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 2
Biswajit Sahu What is issue?
3rd Feb 2021, 7:11 PM
A͢J
A͢J - avatar
+ 2
Biswajit Sahu Why you don't check self in that problem?
3rd Feb 2021, 7:49 PM
A͢J
A͢J - avatar
+ 1
Check its correct or not I Am AJ !
3rd Feb 2021, 7:43 PM
Biswajit Sahu
Biswajit Sahu - avatar
+ 1
Ya i also checked I Am AJ ! .. But i find some different answers. You hv any better idea 💡.
3rd Feb 2021, 7:52 PM
Biswajit Sahu
Biswajit Sahu - avatar
+ 1
Kala Anas this thread is very old Your code lacks indention, at least how you posted it. You have two methods called __add__, the second has to be __str__ or __repr__. Your second method has some more errors, see original post for correct code
11th Jun 2021, 6:04 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
Biswajit Sahu I found right answer so there is no issue.
3rd Feb 2021, 8:16 PM
A͢J
A͢J - avatar
0
class juice: def__init__(self, name, capacity) : self.name = name self.capacity = capacity def__add__(self, obj): name=self.name+"&"+obj.name cap =self. capacity+obj. capacity return juice(name, cap) def__add__(self): return (self name) +'(' +str(self. capacity+'L' )) a =juice('orange', 1.5) b=juice('apple', 2.0) result = a+b print(result)
11th Jun 2021, 5:45 PM
Kala Anas