Решение на Родословно дърво от Данаил Димитров

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

Към профила на Данаил Димитров

Резултати

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

Код

class Person:
list_of_people = []
def __init__(self, name, birth_year,
gender, father=None,
mother=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.father = father
self.mother = mother
if name:
Person.list_of_people.append(self)
def get_sisters(self):
sisters = []
for person in [perrsone for perrsone in Person.list_of_people
if perrsone.gender == 'F' and perrsone != self]:
if self.mother == person.mother and person.mother:
sisters.append(person)
elif self.father == person.father and person.father:
sisters.append(person)
return list(set(sisters))
def get_brothers(self):
brothers = []
for person in [perrsone for perrsone in Person.list_of_people
if perrsone.gender == 'M' and perrsone != self]:
if self.father == person.father and person.father:
brothers.append(person)
elif self.mother == person.mother and person.mother:
brothers.append(person)
return list(set(brothers))
def children(self, gender=""):
if self.gender == 'M':
person_parent = Person(name='', birth_year='',
gender='', father=self)
else:
person_parent = Person(name='', birth_year='',
gender='', mother=self)
if gender == 'M':
children = person_parent.get_brothers()
del person_parent
return children
elif gender == 'F':
children = person_parent.get_sisters()
del person_parent
return children
else:
children = set(person_parent.get_brothers() +
person_parent.get_sisters())
del person_parent
return list(set(children))
def is_direct_successor(self, person):
if person.father == self:
return True
elif person.mother == self:
return True
else:
return False

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

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

OK

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

Данаил обнови решението на 30.03.2013 02:48 (преди над 11 години)

+class Person:
+
+ list_of_people = []
+
+ def __init__(self, name, birth_year,
+ gender, father=None,
+ mother=None):
+
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.father = father
+ self.mother = mother
+ if name:
+ Person.list_of_people.append(self)
+
+ def get_sisters(self):
+
+ sisters = []
+ for person in [perrsone for perrsone in Person.list_of_people
+ if perrsone.gender == 'F' and perrsone != self]:
+
+ if self.mother == person.mother and person.mother:
+ sisters.append(person)
+ elif self.father == person.father and person.father:
+ sisters.append(person)
+
+ return list(set(sisters))
+
+ def get_brothers(self):
+
+ brothers = []
+ for person in [perrsone for perrsone in Person.list_of_people
+ if perrsone.gender == 'M' and perrsone != self]:
+ if self.father == person.father and person.father:
+ brothers.append(person)
+ elif self.mother == person.mother and person.mother:
+ brothers.append(person)
+
+ return list(set(brothers))
+
+ def children(self, gender=""):
+
+ if self.gender == 'M':
+ person_parent = Person(name='', birth_year='',
+ gender='', father=self)
+
+ else:
+ person_parent = Person(name='', birth_year='',
+ gender='', mother=self)
+
+ if gender == 'M':
+ children = person_parent.get_brothers()
+ del person_parent
+ return children
+ elif gender == 'F':
+ children = person_parent.get_sisters()
+ del person_parent
+ return children
+
+ else:
+ children = set(person_parent.get_brothers() +
+ person_parent.get_sisters())
+ del person_parent
+ return list(set(children))
+
+ def is_direct_successor(self, person):
+
+ if person.father == self:
+ return True
+
+ elif person.mother == self:
+ return True
+
+ else:
+ return False

Данаил обнови решението на 30.03.2013 09:52 (преди над 11 години)

class Person:
list_of_people = []
def __init__(self, name, birth_year,
gender, father=None,
mother=None):
-
self.name = name
self.birth_year = birth_year
self.gender = gender
self.father = father
self.mother = mother
if name:
Person.list_of_people.append(self)
def get_sisters(self):
-
sisters = []
for person in [perrsone for perrsone in Person.list_of_people
if perrsone.gender == 'F' and perrsone != self]:
if self.mother == person.mother and person.mother:
sisters.append(person)
elif self.father == person.father and person.father:
sisters.append(person)
return list(set(sisters))
def get_brothers(self):
-
brothers = []
for person in [perrsone for perrsone in Person.list_of_people
if perrsone.gender == 'M' and perrsone != self]:
if self.father == person.father and person.father:
brothers.append(person)
elif self.mother == person.mother and person.mother:
brothers.append(person)
return list(set(brothers))
def children(self, gender=""):
-
if self.gender == 'M':
person_parent = Person(name='', birth_year='',
gender='', father=self)
else:
person_parent = Person(name='', birth_year='',
gender='', mother=self)
if gender == 'M':
children = person_parent.get_brothers()
del person_parent
return children
elif gender == 'F':
children = person_parent.get_sisters()
del person_parent
return children
else:
children = set(person_parent.get_brothers() +
person_parent.get_sisters())
del person_parent
return list(set(children))
def is_direct_successor(self, person):
-
if person.father == self:
return True
elif person.mother == self:
return True
else:
return False