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

+9

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

20 Answers

New Answer

+26

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 ๐Ÿ˜Š

+22

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

+8

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)

+8

Thanks Elis Sala

+5

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

+5

Hacker Badshah thanks for help๐Ÿ˜Š

+2

Def __add__(self,n): Self.name+="&"+str(n.name) Self.capacity+=n.capacity Return self.__str__ Print(a.__ad__(b)()

+2

why is my result = a + b wrong

+1

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

+1

var = input("your text goes here")

+1

Apple and orange juice aim only 90% right

+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, 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)

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

0

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

My result a + b has a error

0

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

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

-1