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

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

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

Резултати

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

Код

class Person:
def __init__(self, name, birth_year, gender, mother=None, father=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.mother = mother
self.father = father
self.ListOfChildren = []
if self.mother is not None:
self.mother.ListOfChildren.append(self)
if self.father is not None:
self.father.ListOfChildren.append(self)
def children(self, **kwargs):
if kwargs:
kids = []
for x in self.ListOfChildren:
if x.gender == kwargs['gender']:
kids.append(x)
return kids
else:
return self.ListOfChildren
def get_brothers(self):
FatherKids = set()
MotherKids = set()
if self.father is not None:
FatherKids = {kid for kid in self.father.children()
if (kid is not self) and (kid.gender == 'M')}
if self.mother is not None:
MotherKids = {kid for kid in self.mother.children()
if (kid is not self) and (kid.gender == 'M')}
allChildren = list(MotherKids.union(FatherKids))
return allChildren
def get_sisters(self):
FatherKids = set()
MotherKids = set()
if self.father is not None:
FatherKids = {kid for kid in self.father.children()
if (kid is not self) and (kid.gender == 'F')}
if self.mother is not None:
MotherKids = {kid for kid in self.mother.children()
if (kid is not self) and (kid.gender == 'F')}
allChildren = list(MotherKids.union(FatherKids))
return list(allChildren)
def is_direct_successor(self, successor):
if successor in self.ListOfChildren:
return True
else:
return False

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

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

OK

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

Габриел обнови решението на 01.04.2013 15:05 (преди около 11 години)

+class Person:
+ def __init__(self,name,birth_year,gender,mother = None,father = None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.mother = mother
+ self.father = father
+ self.ListOfChildren = []
+
+ if self.mother != None:
+ self.mother.ListOfChildren.append(self)
+
+ if self.father != None:
+ self.father.ListOfChildren.append(self)
+
+ def children(self,**kwargs):
+ if kwargs:
+ kids = []
+ for x in self.ListOfChildren:
+ if x.gender == kwargs['gender']:
+ kids.append(x)
+ return kids
+
+ else:
+ return self.ListOfChildren
+
+ def get_brothers(self):
+ FatherKids = set()
+ MotherKids = set()
+
+ if self.father != None:
+ FatherKids = {kid for kid in self.father.children() if (kid is not self) and (kid.gender == 'M')}
+ if self.mother != None:
+ MotherKids = {kid for kid in self.mother.children() if (kid is not self) and (kid.gender == 'M')}
+
+ allChildren=list(MotherKids.union(FatherKids))
+ return allChildren
+
+ def get_sisters(self):
+ FatherKids = set()
+ MotherKids = set()
+
+ if self.father != None:
+ FatherKids = {kid for kid in self.father.children() if (kid is not self) and (kid.gender == 'F')}
+
+ if self.mother != None:
+ MotherKids = {kid for kid in self.mother.children() if (kid is not self) and (kid.gender == 'F')}
+
+ allChildren=list(MotherKids.union(FatherKids))
+
+ return list(allChildren)
+
+ def is_direct_successor(self,successor):
+
+ if successor in self.ListOfChildren:
+ return True
+
+ else:
+ return False

Габриел обнови решението на 01.04.2013 15:26 (преди около 11 години)

class Person:
- def __init__(self,name,birth_year,gender,mother = None,father = None):
+ def __init__(self, name, birth_year, gender, mother=None, father=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.mother = mother
self.father = father
self.ListOfChildren = []
- if self.mother != None:
+ if self.mother is not None:
self.mother.ListOfChildren.append(self)
- if self.father != None:
+ if self.father it not None:
self.father.ListOfChildren.append(self)
- def children(self,**kwargs):
+ def children(self, **kwargs):
if kwargs:
kids = []
for x in self.ListOfChildren:
if x.gender == kwargs['gender']:
kids.append(x)
return kids
-
- else:
+
+ else:
return self.ListOfChildren
def get_brothers(self):
FatherKids = set()
MotherKids = set()
- if self.father != None:
- FatherKids = {kid for kid in self.father.children() if (kid is not self) and (kid.gender == 'M')}
- if self.mother != None:
- MotherKids = {kid for kid in self.mother.children() if (kid is not self) and (kid.gender == 'M')}
+ if self.father is not None:
+ FatherKids = {kid for kid in self.father.children()
+ if (kid is not self) and (kid.gender == 'M')}
+ if self.mother is not None:
+ MotherKids = {kid for kid in self.mother.children()
+ if (kid is not self) and (kid.gender == 'M')}
- allChildren=list(MotherKids.union(FatherKids))
+ allChildren = list(MotherKids.union(FatherKids))
return allChildren
def get_sisters(self):
FatherKids = set()
MotherKids = set()
- if self.father != None:
- FatherKids = {kid for kid in self.father.children() if (kid is not self) and (kid.gender == 'F')}
+ if self.father is not None:
+ FatherKids = {kid for kid in self.father.children()
+ if (kid is not self) and (kid.gender == 'F')}
- if self.mother != None:
- MotherKids = {kid for kid in self.mother.children() if (kid is not self) and (kid.gender == 'F')}
+ if self.mother is not None:
+ MotherKids = {kid for kid in self.mother.children()
+ if (kid is not self) and (kid.gender == 'F')}
- allChildren=list(MotherKids.union(FatherKids))
+ allChildren = list(MotherKids.union(FatherKids))
return list(allChildren)
- def is_direct_successor(self,successor):
-
+ def is_direct_successor(self, successor):
+
if successor in self.ListOfChildren:
return True
else:
- return False
+ return False

Габриел обнови решението на 01.04.2013 15:28 (преди около 11 години)

class Person:
def __init__(self, name, birth_year, gender, mother=None, father=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.mother = mother
self.father = father
self.ListOfChildren = []
if self.mother is not None:
self.mother.ListOfChildren.append(self)
- if self.father it not None:
+ if self.father is not None:
self.father.ListOfChildren.append(self)
def children(self, **kwargs):
if kwargs:
kids = []
for x in self.ListOfChildren:
if x.gender == kwargs['gender']:
kids.append(x)
return kids
else:
return self.ListOfChildren
def get_brothers(self):
FatherKids = set()
MotherKids = set()
if self.father is not None:
FatherKids = {kid for kid in self.father.children()
if (kid is not self) and (kid.gender == 'M')}
if self.mother is not None:
MotherKids = {kid for kid in self.mother.children()
if (kid is not self) and (kid.gender == 'M')}
allChildren = list(MotherKids.union(FatherKids))
return allChildren
def get_sisters(self):
FatherKids = set()
MotherKids = set()
if self.father is not None:
FatherKids = {kid for kid in self.father.children()
if (kid is not self) and (kid.gender == 'F')}
if self.mother is not None:
MotherKids = {kid for kid in self.mother.children()
if (kid is not self) and (kid.gender == 'F')}
allChildren = list(MotherKids.union(FatherKids))
return list(allChildren)
def is_direct_successor(self, successor):
if successor in self.ListOfChildren:
return True
else:
return False