Михаил обнови решението на 28.03.2013 23:11 (преди над 11 години)
+class Person:
+ def __init__(self, name, birth_year, gender, father=None, mother=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.childs = []
+ if father is not None:
+ self.father = father
+ father.childs.append(self)
+ if mother is not None:
+ self.mother = mother
+ mother.childs.append(self)
+
+ def get_brothers(self):
+ all_children = list(set(self.father.childs) | set(self.mother.childs))
+ brothers = []
+ for child in all_children:
+ if child.gender == "M" and self is not child:
+ brothers.append(child)
+ return brothers
+
+ def get_sisters(self):
+ all_children = list(set(self.father.childs) | set(self.mother.childs))
+ sisters = []
+ for child in all_children:
+ if child.gender == "F" and self is not child:
+ sisters.append(child)
+ return sisters
+
+ def children(self, gender="All"):
+ if(gender == "All"):
+ return self.childs
+ else:
+ return [child for child in self.childs if child.gender == gender]
+
+ def is_direct_successor(self, person):
+ if person in self.childs:
+ return True
+ else:
+ return False