+ 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

2nd Nov 2020, 2:50 AM
Hafizhul Qisthi M
Hafizhul Qisthi M - avatar
2 Answers
+ 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.
2nd Nov 2020, 3:49 AM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
0
oh thank you for helping. now it works
3rd Nov 2020, 6:46 AM
Hafizhul Qisthi M
Hafizhul Qisthi M - avatar