+ 2
class polymorphism
hallo everyone, can someone check this code. This code is contained in the theory of the course material, but it looks like there is an error so the code cannot run. Maybe the error is in the space, but I don't know which part to correct class Car: def fuel(self): return 'gas' class Honda(Car): pass class Tesla(Car): def fuel(self): return 'electricity' def get_fuel(car): print(car.fuel()) get_fuel(Tesla()) get_fuel(Honda()) >>> 'electricity'>>> 'gas
2 Antworten
+ 1
The get_fuel function should be a free function, not a member of class Tesla. You should reduce indentation for the two lines containing it.
0
oh thank you for helping. now it works