-
Notifications
You must be signed in to change notification settings - Fork 0
/
go_around_the_tree.py
54 lines (45 loc) · 1.72 KB
/
go_around_the_tree.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import annotations
from typing import Optional
class Spaceman:
def __init__(
self,
name: str,
space_experience: int,
father: Optional[Spaceman] = None,
mother: Optional[Spaceman] = None,
):
self.name = name
self.space_experience = space_experience
self.father = father
self.mother = mother
class DynastyExperienceCounter:
def __init__(self, spaceman: Spaceman):
self.root = spaceman
self.total_experience: int = 0
def count_dynasty_experience(self):
# Доработайте метод, чтобы он считал
# суммарный опыт династии космонавтов.
self.total_experience += self.root.space_experience
if self.root.father:
self.total_experience += (DynastyExperienceCounter
(self.root.father).count_dynasty_experience())
if self.root.mother:
self.total_experience += (DynastyExperienceCounter
(self.root.mother).count_dynasty_experience())
return self.total_experience
yu_a_tatarin = Spaceman(
name='Юрий Алексеевич Макарин',
space_experience=10,
father=Spaceman(
name='Алексей Михайлович Макарин',
space_experience=25,
mother=Spaceman(
name='Евгения Владимировна Беляева',
space_experience=1
)
),
mother=Spaceman('Ангелина Васильевна Черенкова', 5)
)
counter = DynastyExperienceCounter(yu_a_tatarin)
result = counter.count_dynasty_experience()
print(result)