I'm still studying polymorphism in python. I tried to add color attribute based on this code, but I failed. Here is my code:
class Shape:
width = 0
height = 0
color = 0
def area(self):
print('Parent class Area ... ')
def get_color(self):
print('Parent class Color ...')
class Rectangle(Shape):
def __init__(self, w, h, c):
self.width = w
self.height = h
self.color = c
def area(self):
print('Area of the Rectangle is : ', self.width*self.height)
def get_color(self):
print('Color of Rectangle: ', self.color)
class Triangle(Shape):
def __init__(self, w, h, c):
self.width = w
self.height = h
self.color = c
def area(self):
print('Color of Rectangle: ', self.color)
print('Area of the Triangle is : ', (self.width*self.height)/2)
def color(self):
print('Color of Triangle: ', self.color)
Result:
TypeError: 'str' object is not callable
I'm still newbie in this part. Thank you for your helps before ;)
TypeErros.. but I suspect this: your classes cannot have variables and methods with the same name, for example `color´