Решение на Родословно дърво от Георги Горанов

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

Към профила на Георги Горанов

Резултати

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

Код

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.children() or self in other.children():
return True
else:
return False

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

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

OK

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

Георги обнови решението на 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

Георги обнови решението на 01.04.2013 15:58 (преди около 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()
- ):
+ if other in self.children() or self in other.children():
return True
else:
return False