juice maker | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

juice maker

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 class Juice: def __init__(self, name, capacity): self.name = name self.capacity = capacity def __add__(self,other): new_name = self.name +"&"+ other.name new_capacity= self.capacity + other.capacity return Juice(new_name , str(new_capacity)+'L') a = Juice('Orange', 1.5) b = Juice('Apple', 2.0) result = a + b print(result.name,(result.capacity)) capacity: 3.5 The names have been combined using an & symbol.

7th Nov 2021, 11:39 PM
veena
veena - avatar
2 Answers
+ 2
Is there a problem with that code you need help with? Also please, next time use the relevant tags section proportionally https://code.sololearn.com/W3uiji9X28C1/?ref=app
8th Nov 2021, 1:36 AM
Ipang
0
May you need there return Juice(new_name , "("+str(new_capacity)+'L)') ?
8th Nov 2021, 8:40 AM
Jayakrishna 🇮🇳