Георги обнови решението на 29.03.2013 02:02 (преди над 11 години)
+class Person:
+ name = None
+ birth_year = None
+ gender = None
+ father = None
+ mother = None
+ persons = []
+
+ def __init__(self, name, birth_year, gender, father=None, mother=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ if father and self.birth_year - father.birth_year >= 18:
+ self.father = father
+ if mother and self.birth_year - mother.birth_year >= 18:
+ self.mother = mother
+ Person.persons.append(self)
+
+ def get_brothers(self):
+ brothers = []
+ for brother in Person.persons:
+ if self is not brother and brother.gender == 'M' and ((self.father
+ is not None and self.father is brother.father) or
+ (self.mother is not None and self.mother is brother.mother)):
+ brothers.append(brother)
+ return brothers
+
+ def get_sisters(self):
+ sisters = []
+ for sister in Person.persons:
+ if (
+ self is not sister and sister.gender == 'F' and ((self.father
+ is not None and self.father is sister.father) or
+ (self.mother is not None and self.mother is sister.mother))
+ ):
+ sisters.append(sister)
+ return sisters
+
+ def children(self, gender=None):
+ children = []
+ for child in Person.persons:
+ if child.father is self or child.mother is self:
+ if gender is None:
+ children.append(child)
+ elif child.gender == gender:
+ children.append(child)
+ return children
+
+ def is_direct_successor(self, other):
+ if (
+ other in self.get_brothers() or other in
+ self.get_sisters() or other in self.children()
+ ):
+ return True
+ else:
+ return False