0

Please help me

You are given a Juice class, which has name and capacity properties. You need to complete the code to enable and adding of two Juice objects, resulting in a new Juice object with the combined capacity and names of the two juices being added. For example, if you add an Orange juice with 1.0 capacity and an Apple juice with 2.5 capacity, the resulting juice should have: name: Orange&Apple capacity: 3.5 The names have been combined using an & symbol.

18th Oct 2020, 2:47 AM
Biswajit Sahu
Biswajit Sahu - avatar
10 Answers
+ 4
Can we see your try?
18th Oct 2020, 2:50 AM
Slick
Slick - 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)') a = Juice('Orange', 1.5) b = Juice('Apple', 2.0) result = a + b print(result)
18th Oct 2020, 4:40 AM
Biswajit Sahu
Biswajit Sahu - avatar
+ 1
no... no... just for focus
18th Oct 2020, 4:43 AM
Biswajit Sahu
Biswajit Sahu - avatar
0
You marked your own answer right so I'll assume you got it.
18th Oct 2020, 4:42 AM
Slick
Slick - avatar
0
Please check the code
18th Oct 2020, 4:44 AM
Biswajit Sahu
Biswajit Sahu - avatar
0
You need to define __add__ method for class Juice. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2470/
18th Oct 2020, 4:56 AM
Nikolai Ivanov
Nikolai Ivanov - avatar
0
1st Sep 2021, 7:30 AM
N.priya darsini
0
15th May 2022, 4:37 PM
CAROLINE NYABURU
- 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)
8th Dec 2021, 2:41 PM
Pranav Kamera