+ 2

Help pls 🥺🙏 : python

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) result = a + b print(result) What's wrong with my code

29th Jun 2022, 10:53 AM
Hrithika Reddy
Hrithika Reddy - avatar
2 Respuestas
+ 7
Hrithika Reddy , as lisa already mentioned, you should repeat some parts of the "python core" tutorial. have a look at the oop part, lesson 75.1 and look for magic methods.
29th Jun 2022, 11:15 AM
Lothar
Lothar - avatar
+ 3
Please READ the TASK DESCRIPTION again: In the box it says, we should overload the __add__ operator. Your code has not defined the behavior for __add__ yet.
29th Jun 2022, 11:00 AM
Lisa
Lisa - avatar