Решение на Родословно дърво от Кристиян Якимов

Обратно към всички решения

Към профила на Кристиян Якимов

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 11 успешни тест(а)
  • 0 неуспешни тест(а)

Код

class Person:
def __init__(self, name, gender, birth_year, father=None, mother=None):
self.name = name
self.gender = gender
self.birth_year = birth_year
self.father = father
if father != None:
father.inheritors.append(self)
self.mother = mother
if mother != None:
mother.inheritors.append(self)
self.inheritors = []
def get_brothers(self):
return list(set([x for x in self.father.inheritors
if x.gender == 'M' and x != self] +
[x for x in self.mother.inheritors
if x.gender == 'M' and x != self]))
def get_sisters(self):
return list(set([x for x in self.father.inheritors
if x.gender == 'F' and x != self] +
[x for x in self.mother.inheritors
if x.gender == 'F' and x != self]))
def children(self, gender=''):
if gender == 'F' or gender == 'M':
return [x for x in self.inheritors if gender == x.gender]
else:
return [x for x in self.inheritors]
def is_direct_successor(self, relative):
if (relative in self.children()):
return True
else:
return False

Лог от изпълнението

...........
----------------------------------------------------------------------
Ran 11 tests in 0.006s

OK

История (1 версия и 0 коментара)

Кристиян обнови решението на 29.03.2013 20:21 (преди над 11 години)

+class Person:
+
+ def __init__(self, name, gender, birth_year, father=None, mother=None):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.father = father
+ if father != None:
+ father.inheritors.append(self)
+ self.mother = mother
+ if mother != None:
+ mother.inheritors.append(self)
+ self.inheritors = []
+
+ def get_brothers(self):
+ return list(set([x for x in self.father.inheritors
+ if x.gender == 'M' and x != self] +
+ [x for x in self.mother.inheritors
+ if x.gender == 'M' and x != self]))
+
+ def get_sisters(self):
+ return list(set([x for x in self.father.inheritors
+ if x.gender == 'F' and x != self] +
+ [x for x in self.mother.inheritors
+ if x.gender == 'F' and x != self]))
+
+ def children(self, gender=''):
+ if gender == 'F' or gender == 'M':
+ return [x for x in self.inheritors if gender == x.gender]
+ else:
+ return [x for x in self.inheritors]
+
+ def is_direct_successor(self, relative):
+ if (relative in self.children()):
+ return True
+ else:
+ return False