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

+14

# 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

+47

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 😊

+52

#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)())

+31

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)

+12

+8

+5

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

+5

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)

+5

why is my result = a + b wrong

+2

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

+2

My result a + b has a error

+1

var = input("your text goes here")

+1

Apple and orange juice aim only 90% right

+1

+1

my code is a bit more roundabout than others but it worked. not as elegant but not bad for adopting pieces of others and making it my own! 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(new_name + (str(" ")) + str("(") + ((str((new_capacity))+"L)"))) 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)

+1

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. cclass 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)())

+1

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)())

+1

# here 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,newJuice): self.name += "&" + str(newJuice.name) self.capacity += newJuice.capacity return self.__str__ a = Juice('Orange', 1.5) b = Juice('Apple', 3.0) print(a.__add__(b)())

+1

The simplest solution a = ("Orange") b = ('Apple') print (a+'&'+b+ ' (3.5L)' )

+1

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) print(a.name+'&'+b.name+"", '('+str(a.capacity + b.capacity)+'L)')

+1

lass 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)