-
Notifications
You must be signed in to change notification settings - Fork 0
/
family.py
27 lines (20 loc) · 842 Bytes
/
family.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from relation import Relation
class Family:
def __init__(self):
self._members = {}
def add_member(self, person):
self._members[person.name] = person
def count_relation(self, of_person, relation, whole_family=False):
immediate_sons = len(of_person.relations[relation])
for son in of_person.relations[relation]:
if son.relations[relation]:
immediate_sons += self.count_sons(son, whole_family)
return immediate_sons
def count_sons(self, of_person):
return count_relation(of_person, 'SON')
def count_all_sons(self, of_person):
return count_relation(of_person, 'SON', whole_family=True)
def count_daughters(self, of_person):
return count_relation(of_person, 'DAUGHTER')
def count_all_daughters(self, of_person):
return count_relation(of_person, 'DAUGHTER', whole_family=True)