You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks @HaBeSte! Could you just add a brief description of the reason behind this suggestion?
I would probably suggest to create a Human class instead with some "default" attributes. Otherwise this becomes more an example of "composition" rather than "inheritance".
Composition would be natural in this case:
classMother:
def__init__(self, eye_color: str):
self.eye_color=eye_colorclassFather:
def__init__(self, eye_color: str):
self.eye_color=eye_colorclassChild:
def__init__(self, mother: Mother, father: Father):
self.mother=motherself.father=fatherself.eye_color=self.set_eye_color()
defset_eye_color(self):
"""Set Child eye color based on Mother and Father eye color"""returnself.mother.eye_color+self.father.eye_colorm=Mother("blu")
f=Father("green")
print(Child(m, f).eye_color)
Hi @edoardob90
As I understood the idea behind the task was to see the inheritance as an example, using an example where in real life inheritance played a role. The initial solution bothered me a bit, since it used variables called mother_eye_color, resp. father_eye_color and super() couldn't be used directly, because of the double inheritance. So I sat together with @despadam and we came up with the solution above.
I see your point, when we use "eye" (or human) for inheritance, again it's not really the inheritance from mom and dad as it initially supposed to be the idea. maybe a class called "genes" would make more sense in that context?
The text was updated successfully, but these errors were encountered: