Решение на Родословно дърво от Александър Цветанов

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

Към профила на Александър Цветанов

Резултати

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

Код

class Person():
_name = " "
_birth_date = 0
_gender = " "
father_childrens = []
mother_childrens = []
father_mchilds = []
father_fchilds = []
mother_fchilds = []
mother_mchilds = []
def __init__(self, name, birth_date, gender):
self._name = name
self._birth_date = birth_date
self._gender = gender
def add_children(self, Person):
if self._gender == "Male":
if Person._gender == "Male":
self.father_mchilds.append(Person._name)
elif Person._gender == "Female":
self.father_fchilds.append(Person._name)
self.father_childrens.append(Person._name)
elif self._gender == "Female":
if Person._gender == "Male":
self.mother_mchilds.append(Person._name)
elif Person._gender == "Female":
self.mother_fchilds.append(Person._name)
self.mother_childrens.append(Person._name)
def children(self, gender):
if (self._gender == "Male"):
if (gender == "Male"):
return self.father_mchilds
elif (gender == "Female"):
return self.father_fchilds
else:
return self.father_childrens
elif (self._gender == "Female"):
if (gender == "Male"):
return self.mother_mchilds
elif (gender == "Female"):
return self.mother_fchilds
else:
return self.mother_childrens
else:
return []
def is_direct_successor(self, Person):
if (Person._gender == "Male"):
if self._name in Person.father_childrens:
return True
else:
return False
elif (Person._gender == "Female"):
if self._name in Person.mother_childrens:
return True
else:
return False
def get_brothers(self):
dad = []
mom = []
if (self._gender == "Male"):
if (self._name) in self.father_mchilds:
dad = [x for x in self.father_mchilds if not(x == self._name)]
if (self._name) in self.mother_mchilds:
mom = [x for x in self.mother_mchilds if not(x == self._name)]
return dad + mom
elif (self._gender == "Female"):
if (self._name) in self.father_childrens:
dad = self.father_mchilds
if (self._name) in self.mother_childrens:
mom = self.mother_mchilds
return dad + mom
else:
return []
def get_sisters(self):
dad = []
mom = []
if (self._gender == "Female"):
if (self._name) in self.father_fchilds:
dad = [x for x in self.father_fchilds if not(x == self._name)]
if (self._name) in self.mother_fchilds:
mom = [x for x in self.mother_fchilds if not(x == self._name)]
return dad + mom
elif (self._gender == "Male"):
if (self._name) in self.father_childrens:
dad = self.father_fchilds
if (self._name) in self.mother_childs:
mom = self.mother_fchildren
return dad + mom
else:
return []

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

EEEEEEEEEEE
======================================================================
ERROR: test_attributes (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_children (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_father_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_father_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_has_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_has_no_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_has_no_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_has_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_indirect_successor (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_mother_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

======================================================================
ERROR: test_mother_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-12i9v0j/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() got an unexpected keyword argument 'birth_year'

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

FAILED (errors=11)

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

Александър обнови решението на 01.04.2013 10:39 (преди над 11 години)

+class Person():
+
+ _name = " "
+ _birth_date = 0
+ _gender = " "
+ father_childrens = []
+ mother_childrens = []
+ father_mchilds = []
+ father_fchilds = []
+ mother_fchilds = []
+ mother_mchilds = []
+
+ def __init__(self, name, birth_date, gender):
+ self._name = name
+ self._birth_date = birth_date
+ self._gender = gender
+
+ def add_children(self, Person):
+ if self._gender == "Male":
+ if Person._gender == "Male":
+ self.father_mchilds.append(Person._name)
+ elif Person._gender == "Female":
+ self.father_fchilds.append(Person._name)
+ self.father_childrens.append(Person._name)
+ elif self._gender == "Female":
+ if Person._gender == "Male":
+ self.mother_mchilds.append(Person._name)
+ elif Person._gender == "Female":
+ self.mother_fchilds.append(Person._name)
+ self.mother_childrens.append(Person._name)
+
+ def children(self, gender):
+ if (self._gender == "Male"):
+ if (gender == "Male"):
+ return self.father_mchilds
+ elif (gender == "Female"):
+ return self.father_fchilds
+ else:
+ return self.father_childrens
+ elif (self._gender == "Female"):
+ if (gender == "Male"):
+ return self.mother_mchilds
+ elif (gender == "Female"):
+ return self.mother_fchilds
+ else:
+ return self.mother_childrens
+ else:
+ return []
+
+ def is_direct_successor(self, Person):
+ if (Person._gender == "Male"):
+ if self._name in Person.father_childrens:
+ return True
+ else:
+ return False
+ elif (Person._gender == "Female"):
+ if self._name in Person.mother_childrens:
+ return True
+ else:
+ return False
+
+ def get_brothers(self):
+ dad = []
+ mom = []
+ if (self._gender == "Male"):
+ if (self._name) in self.father_mchilds:
+ dad = [x for x in self.father_mchilds if not(x == self._name)]
+ if (self._name) in self.mother_mchilds:
+ mom = [x for x in self.mother_mchilds if not(x == self._name)]
+ return dad + mom
+ elif (self._gender == "Female"):
+ if (self._name) in self.father_childrens:
+ dad = self.father_mchilds
+ if (self._name) in self.mother_childrens:
+ mom = self.mother_mchilds
+ return dad + mom
+ else:
+ return []
+
+ def get_sisters(self):
+ dad = []
+ mom = []
+ if (self._gender == "Female"):
+ if (self._name) in self.father_fchilds:
+ dad = [x for x in self.father_fchilds if not(x == self._name)]
+ if (self._name) in self.mother_fchilds:
+ mom = [x for x in self.mother_fchilds if not(x == self._name)]
+ return dad + mom
+ elif (self._gender == "Male"):
+ if (self._name) in self.father_childrens:
+ dad = self.father_fchilds
+ if (self._name) in self.mother_childs:
+ mom = self.mother_fchildren
+ return dad + mom
+ else:
+ return []