Can someone please help me with this python code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can someone please help me with this python code?

I created this code to practice using classes and methods because the courses don't explain it very well, but I keep having errors even though I changed the code several times. Could someone please tell me what's wrong with it? https://sololearn.com/compiler-playground/cO1G05EmJh7B/?ref=app

24th Apr 2024, 3:30 PM
Marc Haddad
Marc Haddad - avatar
7 Answers
+ 2
the issue lies in how the display_info methods are managed in the Car and Ferrari classes. The display_info method in the Car class expects four arguments whereas in the Ferrari class the modified method does not correctly utilize the arguments inherited from the superclass. You should use the object's attributes directly within the display_info methods instead of passing them as arguments. here are the two methods to correct : def display_info(self): print("Brand:", self._brand) print("Year:", self.year) print("Color:", self.color) print("Price:", self.__price, "€") def display_info(self): super().display_info() print("Top speed:", self.top_speed, "km/h")
24th Apr 2024, 3:52 PM
piano T
+ 11
Hey everyone, I've noticed a trend where we're leaning too heavily on ChatGPT for answers without really thinking things through ourselves. It's like we're missing out on the joy of problem-solving. Let's make sure we're all pitching in with our own thoughts and ideas to keep our community vibrant and engaging!
24th Apr 2024, 4:09 PM
Chris Coder
Chris Coder - avatar
+ 2
class Car: def __init__(self, brand, year, color, price): self._brand = brand self.year = year self.color = color self.__price = price def display_info(self): print("Brand:", self._brand) print("Year:", self.year) print("Color:", self.color) print("Price:", self.__price, "€") class Ferrari(Car): def __init__(self, brand, year, color, price, top_speed): super().__init__(brand, year, color, price) self.top_speed = top_speed def display_info(self): super().display_info() print("Top speed:", self.top_speed, "km/h") my_car = Ferrari("Ferrari", 1984, "red", 850000, 240) my_car.display_info()
24th Apr 2024, 3:53 PM
Parv
Parv - avatar
+ 2
Chris Coder I love this energy! I'm a bit shy about what I'm making at the moment but I might start sharing soon. The Joy Of Problem Solving 😊
25th Apr 2024, 11:45 PM
Amari Herbert
+ 1
Marc Haddad , Did you edit the original code already? I don't see a problem. If your issue is solved, could you add [Solved] to the title so people know they don't need to help?
25th Apr 2024, 3:19 AM
Rain
Rain - avatar
0
Thanks guys!
24th Apr 2024, 4:35 PM
Marc Haddad
Marc Haddad - avatar
0
Okay, thanks, I'll do it.
25th Apr 2024, 5:13 AM
Marc Haddad
Marc Haddad - avatar