- 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)
8 Antworten
+ 3
What's your question?
+ 2
Biswajit Sahu
What is issue?
+ 2
Biswajit Sahu Why you don't check self in that problem?
+ 1
Check its correct or not I Am AJ !
+ 1
Ya i also checked I Am AJ ! .. But i find some different answers.
You hv any better idea 💡.
+ 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
0
Biswajit Sahu I found right answer so there is no issue.
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)