-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathless06_easy.py
More file actions
57 lines (38 loc) · 1.77 KB
/
Copy pathless06_easy.py
File metadata and controls
57 lines (38 loc) · 1.77 KB
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
#coding utf-8
# Задача - 1
# Опишите несколько классов TownCar, SportCar, WorkCar, PoliceCar
# У каждого класса должны быть следующие аттрибуты:
# speed, color, name, is_police - Булево значение.
# А так же несколько методов: go, stop, turn(direction) - которые должны сообщать,
# о том что машина поехала, остановилась, повернула(куда)
class Car:
def __init__(self, speed, color, name):
self.speed = speed
self.color = color
self.name = name
self._is_police = False
def go(self):
return 'Машина поехала'
def stop(self):
return 'Машина остановилась'
def turn(self, direction = 'В неизвестном направлении'):
return f'Машина повернула {direction}'
def is_police(self):
return self._is_police
class TownCar(Car):
def __init__(self, speed, color, name):
super().__init__(speed, color, name)
class SportCar(Car):
def __init__(self, speed, color, name):
super().__init__(speed, color, name)
class WorkCar(Car):
def __init__(self, speed, color, name):
super().__init__(speed, color, name)
class PoliceCar(Car):
def __init__(self, speed, color, name):
super().__init__(speed, color, name)
self._is_police = True
# Задача - 2
# Посмотрите на задачу-1 подумайте как выделить общие признаки классов
# в родительский и остальные просто наследовать от него.
# Случайно сразу так сделал))