+ 15

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

27th Oct 2020, 5:49 PM
Chahat Singh
Chahat Singh - avatar
43 ответов
+ 55
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 😊
27th Oct 2020, 8:28 PM
Hacker Badshah
Hacker Badshah - avatar
+ 68
#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)())
29th Oct 2020, 10:52 AM
Naafi Ibrahim
Naafi Ibrahim - avatar
+ 40
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)
29th Oct 2020, 9:27 AM
Elis Sala
Elis Sala - avatar
+ 11
Thanks Elis Sala
29th Oct 2020, 9:52 AM
Chahat Singh
Chahat Singh - avatar
+ 8
Hacker Badshah thanks for help😊
28th Oct 2020, 4:15 AM
Chahat Singh
Chahat Singh - avatar
+ 6
why is my result = a + b wrong
2nd Mar 2021, 4:49 AM
Sugavaneshwharar
Sugavaneshwharar - avatar
27th Oct 2020, 6:01 PM
Chahat Singh
Chahat Singh - avatar
+ 4
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 Feb 2021, 11:30 AM
Ronny Karani
Ronny Karani - avatar
+ 4
My result a + b has a error
30th Apr 2021, 9:15 PM
Troy Luckey
Troy Luckey - avatar
+ 2
I have a question how can i put texte where i can write after run the programme in phyton
29th Oct 2020, 9:36 PM
Vinniboy1010 Vincent Labelle
Vinniboy1010 Vincent Labelle - avatar
+ 1
var = input("your text goes here")
30th Oct 2020, 4:37 AM
Elis Sala
Elis Sala - avatar
+ 1
Apple and orange juice aim only 90% right
10th Dec 2020, 3:11 AM
Robert Jefferson
Robert Jefferson - avatar
+ 1
Def __add__(self,n): Self.name+="&"+str(n.name) Self.capacity+=n.capacity Return self.__str__ Print(a.__ad__(b)()
27th Dec 2020, 5:31 PM
Boltayev Davronbek
Boltayev Davronbek - avatar
+ 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)
30th Dec 2020, 8:26 PM
CmplXty
+ 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)())
21st Jan 2021, 5:38 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
+ 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)())
3rd May 2021, 6:39 AM
Amarnaath KN K
Amarnaath KN K - avatar
+ 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)())
15th Jun 2021, 11:22 AM
Madhavareddy
Madhavareddy - avatar
+ 1
The simplest solution a = ("Orange") b = ('Apple') print (a+'&'+b+ ' (3.5L)' )
18th Jul 2021, 10:19 AM
Dev Manchanda
Dev Manchanda - avatar
+ 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)')
19th Sep 2021, 4:05 AM
Hugues Rodrigue Tha Andela
Hugues Rodrigue Tha Andela - avatar
+ 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)
4th Dec 2021, 4:01 PM
miki
miki - avatar