+ 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
7 odpowiedzi
+ 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")
+ 12
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!
+ 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()
+ 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 😊
+ 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?
0
Thanks guys!
0
Rain
Okay, thanks, I'll do it.