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

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

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

Резултати

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

Код

class Person:
def __init__(self, name="", birth_year=0, gender=""):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.brother_list = []
self.sister_list = []
self.children_list = []
def father(self, father_person):
if father_person.gender == "male" and father_person.birth_year + 18 <= self.birth_year:
self.father = father_person
return father_person
else:
return (father_person.name + " can't be father of " + self.name)
def mother(self, mother_person):
if mother_person.gender == "female" and mother_person.birth_year + 18 <= self.birth_year:
self.mother = mother_person
return mother_person
else:
return (mother_person.name + " can't be mother of " + self.name)
def is_brother(self, brother_person):
if self is not brother_person:
if brother_person.gender == "male":
if self.mother is brother_person.mother or self.father is brother_person.father:
if brother_person not in self.brother_list:
self.brother_list.append(brother_person)
if self.gender == "male":
if self not in brother_person.brother_list:
brother_person.brother_list.append(self)
elif self.gender == "female":
if self not in brother_person.sister_list:
brother_person.sister_list.append(self)
def get_brother(self):
return self.brother_list
def is_sister(self, sister_person):
if self is not sister_person:
if sister_person.gender == "female":
if self.mother is sister_person.mother or self.father is sister_person.father:
if sister_person not in self.sister_list:
self.sister_list.append(sister_person)
if self.gender == "male":
if self not in sister_person.brother_list:
sister_person.brother_list.append(self)
elif self.gender == "female":
if self not in sister_person.sister_list:
sister_person.sister_list.append(self)
def get_sister(self):
return self.sister_list
def is_child(self, child_person):
if child_person.mother is self or child_person.father is self:
if child_person not in self.children_list:
self.children_list.append(child_person)
def children(self, gender=""):
if gender == "male":
return_list = []
for child in self.children_list:
if child.gender == "male":
return_list.append(child)
return return_list
elif gender == "female":
return_list = []
for child in self.children_list:
if child.gender == "female":
return_list.append(child)
return return_list
else:
return self.children_list
def is_direct_successor(self, person):
if self is person.father or self is person.mother or person is self.father or person is self.mother:
return True
else:
return False

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

EEEEEEEEEEE
======================================================================
ERROR: test_attributes (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_children (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_father_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_father_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_has_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_has_no_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_has_no_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_has_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_indirect_successor (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_mother_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

======================================================================
ERROR: test_mother_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-1m2elcs/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
TypeError: __init__() got an unexpected keyword argument 'father'

----------------------------------------------------------------------
Ran 11 tests in 0.003s

FAILED (errors=11)

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

Димитър обнови решението на 01.04.2013 16:13 (преди над 11 години)

+class Person:
+
+ def __init__(self, name="", birth_year=0, gender=""):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.brother_list = []
+ self.sister_list = []
+ self.children_list = []
+
+ def father(self, father_person):
+ if father_person.gender == "male" and father_person.birth_year + 18 <= self.birth_year:
+ self.father = father_person
+ return father_person
+ else:
+ return (father_person.name + " can't be father of " + self.name)
+
+ def mother(self, mother_person):
+ if mother_person.gender == "female" and mother_person.birth_year + 18 <= self.birth_year:
+ self.mother = mother_person
+ return mother_person
+ else:
+ return (mother_person.name + " can't be mother of " + self.name)
+
+ def is_brother(self, brother_person):
+ if self is not brother_person:
+ if brother_person.gender == "male":
+ if self.mother is brother_person.mother or self.father is brother_person.father:
+ if brother_person not in self.brother_list:
+ self.brother_list.append(brother_person)
+ if self.gender == "male":
+ if self not in brother_person.brother_list:
+ brother_person.brother_list.append(self)
+ elif self.gender == "female":
+ if self not in brother_person.sister_list:
+ brother_person.sister_list.append(self)
+
+ def get_brother(self):
+ return self.brother_list
+
+ def is_sister(self, sister_person):
+ if self is not sister_person:
+ if sister_person.gender == "female":
+ if self.mother is sister_person.mother or self.father is sister_person.father:
+ if sister_person not in self.sister_list:
+ self.sister_list.append(sister_person)
+ if self.gender == "male":
+ if self not in sister_person.brother_list:
+ sister_person.brother_list.append(self)
+ elif self.gender == "female":
+ if self not in sister_person.sister_list:
+ sister_person.sister_list.append(self)
+
+ def get_sister(self):
+ return self.sister_list
+
+ def is_child(self, child_person):
+ if child_person.mother is self or child_person.father is self:
+ if child_person not in self.children_list:
+ self.children_list.append(child_person)
+
+ def children(self, gender=""):
+ if gender == "male":
+ return_list = []
+ for child in self.children_list:
+ if child.gender == "male":
+ return_list.append(child)
+ return return_list
+ elif gender == "female":
+ return_list = []
+ for child in self.children_list:
+ if child.gender == "female":
+ return_list.append(child)
+ return return_list
+ else:
+ return self.children_list
+
+ def is_direct_successor(self, person):
+ if self is person.father or self is person.mother or person is self.father or person is self.mother:
+ return True
+ else:
+ return False