Рейхан обнови решението на 01.04.2013 00:48 (преди над 11 години)
+class Person:
+ list_of_persons = list()
+ def __init__(self, name, birth_year, gender, mother, father):
+ if gender is not "male" and gender is not "female":
+ print("Unknown gender")
+ elif mother is not None and birth_year - mother.birth_year < 18:
+ print("Diff between mother age and children age is too small")
+ elif mother is not None and mother.gender is not "female":
+ print("Mother is not of female gender!")
+ elif father is not None and birth_year - father.birth_year < 18:
+ print("Diff between father age and children age is too small")
+ elif father is not None and father.gender is not "male":
+ print("Father is not of male gender!")
+ else:
+ self.mother = mother
+ self.father = father
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ Person.list_of_persons.append(self)
+ #print("Person {} created".format(name))
+
+ def get_brothers(self):
+ list_of_brothers = list()
+ for person in Person.list_of_persons:
+ if person is not self and person.mother is self.mother and person.gender is "male":
+ list_of_brothers.append(person)
+ elif person is not self and person.father is self.father and person.gender is "male":
+ list_of_brothers.append(person)
+ return list_of_brothers
+
+ def get_sisters(self):
+ list_of_sisters = list()
+ for person in Person.list_of_persons:
+ if person is not self and person.mother is self.mother and person.gender is "female":
+ list_of_sisters.append(person)
+ elif person is not self and person.father is self.father and person.gender is "female":
+ list_of_sisters.append(person)
+ return list_of_sisters
+
+ def children(self, gender = ""):
+ list_of_children = list()
+ for person in Person.list_of_persons:
+ if person.mother is not None and person.mother is self:
+ if gender == "":
+ list_of_children.append(person)
+ elif gender == "male" and person.gender == "male":
+ list_of_children.append(person)
+ elif gender == "female" and person.gender == "female":
+ list_of_children.append(person)
+ elif person.father is not None and person.father is self:
+ if gender == "":
+ list_of_children.append(person)
+ elif gender == "male" and person.gender == "male":
+ list_of_children.append(person)
+ elif gender == "female" and person.gender == "female":
+ list_of_children.append(person)
+ return list_of_children
+
+ def is_direct_successor(self, otherPerson):
+ for person in self.children():
+ if otherPerson is perosn:
+ return True
+ for person in otherPerson.children():
+ if self is person:
+ return True
+ return False