Решение на Родословно дърво от Рейхан Садък

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

Към профила на Рейхан Садък

Резултати

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

Код

class Person:
list_of_persons = list()
def __init__(self, name, birth_year, gender, mother, father):
if gender is not "male" and gender is not "female":
print("Unknown gender")
elif mother is not None and birth_year - mother.birth_year < 18:
print("Diff between mother age and children age is too small")
elif mother is not None and mother.gender is not "female":
print("Mother is not of female gender!")
elif father is not None and birth_year - father.birth_year < 18:
print("Diff between father age and children age is too small")
elif father is not None and father.gender is not "male":
print("Father is not of male gender!")
else:
self.mother = mother
self.father = father
self.name = name
self.birth_year = birth_year
self.gender = gender
Person.list_of_persons.append(self)
#print("Person {} created".format(name))
def get_brothers(self):
list_of_brothers = list()
for person in Person.list_of_persons:
if person is not self and person.mother is self.mother and person.gender is "male":
list_of_brothers.append(person)
elif person is not self and person.father is self.father and person.gender is "male":
list_of_brothers.append(person)
return list_of_brothers
def get_sisters(self):
list_of_sisters = list()
for person in Person.list_of_persons:
if person is not self and person.mother is self.mother and person.gender is "female":
list_of_sisters.append(person)
elif person is not self and person.father is self.father and person.gender is "female":
list_of_sisters.append(person)
return list_of_sisters
def children(self, gender = ""):
list_of_children = list()
for person in Person.list_of_persons:
if person.mother is not None and person.mother is self:
if gender == "":
list_of_children.append(person)
elif gender == "male" and person.gender == "male":
list_of_children.append(person)
elif gender == "female" and person.gender == "female":
list_of_children.append(person)
elif person.father is not None and person.father is self:
if gender == "":
list_of_children.append(person)
elif gender == "male" and person.gender == "male":
list_of_children.append(person)
elif gender == "female" and person.gender == "female":
list_of_children.append(person)
return list_of_children
def is_direct_successor(self, otherPerson):
for person in self.children():
if otherPerson is perosn:
return True
for person in otherPerson.children():
if self is person:
return True
return False

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

EEEEEEEEEEE
======================================================================
ERROR: test_attributes (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_children (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_father_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_father_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_has_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_has_no_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_has_no_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_has_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_indirect_successor (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_mother_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

======================================================================
ERROR: test_mother_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-k6txpg/test.py", line 7, in setUp
    self.adam = solution.Person(name='Adam', gender='M', birth_year=0)
TypeError: __init__() missing 2 required positional arguments: 'mother' and 'father'

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

FAILED (errors=11)

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

Рейхан обнови решението на 01.04.2013 00:48 (преди над 11 години)

+class Person:
+ list_of_persons = list()
+ def __init__(self, name, birth_year, gender, mother, father):
+ if gender is not "male" and gender is not "female":
+ print("Unknown gender")
+ elif mother is not None and birth_year - mother.birth_year < 18:
+ print("Diff between mother age and children age is too small")
+ elif mother is not None and mother.gender is not "female":
+ print("Mother is not of female gender!")
+ elif father is not None and birth_year - father.birth_year < 18:
+ print("Diff between father age and children age is too small")
+ elif father is not None and father.gender is not "male":
+ print("Father is not of male gender!")
+ else:
+ self.mother = mother
+ self.father = father
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ Person.list_of_persons.append(self)
+ #print("Person {} created".format(name))
+
+ def get_brothers(self):
+ list_of_brothers = list()
+ for person in Person.list_of_persons:
+ if person is not self and person.mother is self.mother and person.gender is "male":
+ list_of_brothers.append(person)
+ elif person is not self and person.father is self.father and person.gender is "male":
+ list_of_brothers.append(person)
+ return list_of_brothers
+
+ def get_sisters(self):
+ list_of_sisters = list()
+ for person in Person.list_of_persons:
+ if person is not self and person.mother is self.mother and person.gender is "female":
+ list_of_sisters.append(person)
+ elif person is not self and person.father is self.father and person.gender is "female":
+ list_of_sisters.append(person)
+ return list_of_sisters
+
+ def children(self, gender = ""):
+ list_of_children = list()
+ for person in Person.list_of_persons:
+ if person.mother is not None and person.mother is self:
+ if gender == "":
+ list_of_children.append(person)
+ elif gender == "male" and person.gender == "male":
+ list_of_children.append(person)
+ elif gender == "female" and person.gender == "female":
+ list_of_children.append(person)
+ elif person.father is not None and person.father is self:
+ if gender == "":
+ list_of_children.append(person)
+ elif gender == "male" and person.gender == "male":
+ list_of_children.append(person)
+ elif gender == "female" and person.gender == "female":
+ list_of_children.append(person)
+ return list_of_children
+
+ def is_direct_successor(self, otherPerson):
+ for person in self.children():
+ if otherPerson is perosn:
+ return True
+ for person in otherPerson.children():
+ if self is person:
+ return True
+ return False