Решение на Родословно дърво от Красимира Божанова

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

Към профила на Красимира Божанова

Резултати

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

Код

class Person:
def __init__(self, name, birth_year, gender, father=None, mother=None):
self.name, self.birth_year, self.gender = name, birth_year, gender
self.mother, self.father = mother, father
for parent in [father, mother]:
if parent:
parent.add_children(self)
self.children_list = []
def add_children(self, *args):
self.children_list.extend(args)
def children(self, gender=""):
return [child for child in self.children_list
if not gender or child.gender == gender]
def siblings(self, gender=""):
parents_children = []
for parent in [self.father, self.mother]:
if parent:
parents_children.extend(parent.children(gender))
return set([child for child in parents_children if child is not self])
def get_brothers(self):
return list(self.siblings("M"))
def get_sisters(self):
return list(self.siblings("F"))
def is_direct_successor(self, person):
return person in self.children() or self in person.children()

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

...........
----------------------------------------------------------------------
Ran 11 tests in 0.007s

OK

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

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

+class Person:
+
+ def __init__(self, name, birth_year, gender,
+ father=None, mother=None):
+ self.name, self.birth_year, self.gender = name, birth_year, gender
+ self.mother, self.father = mother, father
+ if self.mother:
+ mother.add_children(self)
+ if self.father:
+ father.add_children(self)
+ self.children_list = []
+
+ def add_children(self, *args):
+ self.children_list.extend(args)
+
+ def children(self, gender=""):
+ return [child for child in self.children_list
+ if not gender or child.gender == gender]
+
+ def siblings(self, gender=""):
+ parents_children = []
+ if self.mother:
+ parents_children.extend(self.mother.children(gender))
+ if self.father:
+ parents_children.extend(self.father.children(gender))
+ return set([child for child in parents_children if child is not self])
+
+ def get_brothers(self):
+ return list(self.siblings("M"))
+
+ def get_sisters(self):
+ return list(self.siblings("F"))
+
+ def is_direct_successor(self, person):
+ return person in self.children() or self in person.children()

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

class Person:
def __init__(self, name, birth_year, gender,
father=None, mother=None):
self.name, self.birth_year, self.gender = name, birth_year, gender
self.mother, self.father = mother, father
- if self.mother:
- mother.add_children(self)
- if self.father:
- father.add_children(self)
+ for parent in [father, mother]:
+ if parent:
+ parent.add_children(self)
self.children_list = []
def add_children(self, *args):
self.children_list.extend(args)
def children(self, gender=""):
return [child for child in self.children_list
if not gender or child.gender == gender]
def siblings(self, gender=""):
parents_children = []
- if self.mother:
- parents_children.extend(self.mother.children(gender))
- if self.father:
- parents_children.extend(self.father.children(gender))
+ for parent in [self.father, self.mother]:
+ if parent:
+ parents_children.extend(parent.children(gender))
return set([child for child in parents_children if child is not self])
def get_brothers(self):
return list(self.siblings("M"))
def get_sisters(self):
return list(self.siblings("F"))
def is_direct_successor(self, person):
return person in self.children() or self in person.children()

Красимира обнови решението на 01.04.2013 00:57 (преди над 11 години)

class Person:
- def __init__(self, name, birth_year, gender,
- father=None, mother=None):
+ def __init__(self, name, birth_year, gender, father=None, mother=None):
self.name, self.birth_year, self.gender = name, birth_year, gender
self.mother, self.father = mother, father
for parent in [father, mother]:
if parent:
parent.add_children(self)
self.children_list = []
def add_children(self, *args):
self.children_list.extend(args)
def children(self, gender=""):
return [child for child in self.children_list
if not gender or child.gender == gender]
def siblings(self, gender=""):
parents_children = []
for parent in [self.father, self.mother]:
if parent:
parents_children.extend(parent.children(gender))
return set([child for child in parents_children if child is not self])
def get_brothers(self):
return list(self.siblings("M"))
def get_sisters(self):
return list(self.siblings("F"))
def is_direct_successor(self, person):
return person in self.children() or self in person.children()