Александър обнови решението на 01.04.2013 10:39 (преди над 11 години)
+class Person():
+
+ _name = " "
+ _birth_date = 0
+ _gender = " "
+ father_childrens = []
+ mother_childrens = []
+ father_mchilds = []
+ father_fchilds = []
+ mother_fchilds = []
+ mother_mchilds = []
+
+ def __init__(self, name, birth_date, gender):
+ self._name = name
+ self._birth_date = birth_date
+ self._gender = gender
+
+ def add_children(self, Person):
+ if self._gender == "Male":
+ if Person._gender == "Male":
+ self.father_mchilds.append(Person._name)
+ elif Person._gender == "Female":
+ self.father_fchilds.append(Person._name)
+ self.father_childrens.append(Person._name)
+ elif self._gender == "Female":
+ if Person._gender == "Male":
+ self.mother_mchilds.append(Person._name)
+ elif Person._gender == "Female":
+ self.mother_fchilds.append(Person._name)
+ self.mother_childrens.append(Person._name)
+
+ def children(self, gender):
+ if (self._gender == "Male"):
+ if (gender == "Male"):
+ return self.father_mchilds
+ elif (gender == "Female"):
+ return self.father_fchilds
+ else:
+ return self.father_childrens
+ elif (self._gender == "Female"):
+ if (gender == "Male"):
+ return self.mother_mchilds
+ elif (gender == "Female"):
+ return self.mother_fchilds
+ else:
+ return self.mother_childrens
+ else:
+ return []
+
+ def is_direct_successor(self, Person):
+ if (Person._gender == "Male"):
+ if self._name in Person.father_childrens:
+ return True
+ else:
+ return False
+ elif (Person._gender == "Female"):
+ if self._name in Person.mother_childrens:
+ return True
+ else:
+ return False
+
+ def get_brothers(self):
+ dad = []
+ mom = []
+ if (self._gender == "Male"):
+ if (self._name) in self.father_mchilds:
+ dad = [x for x in self.father_mchilds if not(x == self._name)]
+ if (self._name) in self.mother_mchilds:
+ mom = [x for x in self.mother_mchilds if not(x == self._name)]
+ return dad + mom
+ elif (self._gender == "Female"):
+ if (self._name) in self.father_childrens:
+ dad = self.father_mchilds
+ if (self._name) in self.mother_childrens:
+ mom = self.mother_mchilds
+ return dad + mom
+ else:
+ return []
+
+ def get_sisters(self):
+ dad = []
+ mom = []
+ if (self._gender == "Female"):
+ if (self._name) in self.father_fchilds:
+ dad = [x for x in self.father_fchilds if not(x == self._name)]
+ if (self._name) in self.mother_fchilds:
+ mom = [x for x in self.mother_fchilds if not(x == self._name)]
+ return dad + mom
+ elif (self._gender == "Male"):
+ if (self._name) in self.father_childrens:
+ dad = self.father_fchilds
+ if (self._name) in self.mother_childs:
+ mom = self.mother_fchildren
+ return dad + mom
+ else:
+ return []