-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask9.py
60 lines (43 loc) · 1.29 KB
/
task9.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
55
56
57
58
59
60
class Figure:
name: str
color: str
def info(self):
print(self.name, self.color)
print()
class Triangle(Figure):
def __init__(self, name: str, color: str):
self.name = name
self.color = color
def info(self):
print("I am triangle, hi!")
Figure.info(self)
class Circle(Figure):
def __init__(self, name: str, color: str):
self.name = name
self.color = color
def info(self):
print("I am circle, hi!")
Figure.info(self)
figures: [Figure] = [Circle("best circle", "green"), Triangle("best triangle", "yellow")]
for f in figures:
f.info()
class TrainTravel:
cost: int = 100500
destintation: str = "Urupinsk"
class Human:
money: int
name: str
def __init__(self, money: int, name: str):
self.money = money
self.name = name
def buy_ticket(self, destination: TrainTravel):
if self.money < destination.cost:
print("Not enough money!")
else:
self.money -= destination.cost
print(self.name, " buy ticket to ", destination.destintation, " and now has ", self.money)
city: TrainTravel = TrainTravel()
jack: Human = Human(3242, "Jack")
tina: Human = Human(100501, "Tina")
jack.buy_ticket(city)
tina.buy_ticket(city)