How to solve juice maker in python!!?? | SoloLearn: Learn to code for FREE!

+6

How to solve juice maker in python!!??

I am unable to solve one of the python code ,which I have recently posted . Please check my post and anyone can help me in this

10/27/2020 5:49:43 PM

Chahat Singh

8 Answers

New Answer

+5

You just have to create a method which take two object mix their name and capacity and make a new object. def __add__(self,other): #Adding Name new_name = self.name+"&"+other.name #Adding Capacity new_capacity = self.capacity+other.capacity #Returning New Object return Juice(new_name,new_capacity) Hope It Helps You 😊

+5

https://www.sololearn.com/discuss/2564862/?ref=app

+5

Thanks Elis Sala

+4

Hacker Badshah thanks for help😊

+4

#Here's my solution to the #problem. Hope it'll suffice. 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,newJuice): self.name += "&" + str(newJuice.name) self.capacity += newJuice.capacity return self.__str__ a = Juice('Orange', 1.5) b = Juice('Apple', 2.0) print(a.__add__(b)())

+2

the following is my solution: 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)

0

I have a question how can i put texte where i can write after run the programme in phyton

0

var = input("your text goes here")