From 2afd41de0f0c48c492e57e0946fd8d6e6a8fcd9f Mon Sep 17 00:00:00 2001 From: "d.zashivalov" Date: Wed, 20 Apr 2022 15:06:07 +0300 Subject: [PATCH] Lesson_6 --- lesson_6/6-1.py | 32 ++++++++++++++++++++ lesson_6/6-2.py | 12 ++++++++ lesson_6/6-3.py | 25 ++++++++++++++++ lesson_6/6-4.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ lesson_6/6-5.py | 38 ++++++++++++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 lesson_6/6-1.py create mode 100644 lesson_6/6-2.py create mode 100644 lesson_6/6-3.py create mode 100644 lesson_6/6-4.py create mode 100644 lesson_6/6-5.py diff --git a/lesson_6/6-1.py b/lesson_6/6-1.py new file mode 100644 index 0000000..3ba9031 --- /dev/null +++ b/lesson_6/6-1.py @@ -0,0 +1,32 @@ +from time import sleep + + +def out_red(text): + print("\033[31m {}".format(text)) + + +def out_yellow(text): + print("\033[33m {}".format(text)) + + +def out_green(text): + print("\033[32m {}".format(text)) + + +class TrafficLight: + __color = ['red', 'green', 'yellow'] + + def running (self): + while True: + out_red('RED') + sleep(7) + out_yellow('YELLOW') + sleep(2) + out_green('GREEN') + sleep(7) + out_yellow('YELLOW') + sleep(2) + + +TrafficLight = TrafficLight() +TrafficLight.running() \ No newline at end of file diff --git a/lesson_6/6-2.py b/lesson_6/6-2.py new file mode 100644 index 0000000..22ae848 --- /dev/null +++ b/lesson_6/6-2.py @@ -0,0 +1,12 @@ +class Road: + def __init__(self, length, width): + self._length = length + self._width = width + + def profit(self, weight=25, thickness=5): + return f'{self._length} m * {self._width} m * {weight} kg * {thickness} sm =' \ + f'{(self._length * self._width * weight * thickness) / 1000} t' + + +road_1 = Road(5000, 20) +print(road_1.profit()) diff --git a/lesson_6/6-3.py b/lesson_6/6-3.py new file mode 100644 index 0000000..16c931f --- /dev/null +++ b/lesson_6/6-3.py @@ -0,0 +1,25 @@ +class Worker: + + def __init__(self, name, surname, position, wage, bonus): + self.name = name + self.surname = surname + self.position = position + self._income = {"wage": wage, "bonus": bonus} + + +class Position(Worker): + + def __init__(self, name, surname, position, wage, bonus): + super().__init__(name, surname, position, wage, bonus) + + def get_full_name(self): + return self.name + ' ' + self.surname + + def get_total_income(self): + return self._income.get('wage') + self._income.get('bonus') + + +a = Position('John', 'Johnson', 'Programmer', 100000, 40000) +print(a.get_full_name()) +print(a.position) +print(a.get_total_income()) \ No newline at end of file diff --git a/lesson_6/6-4.py b/lesson_6/6-4.py new file mode 100644 index 0000000..4ba2962 --- /dev/null +++ b/lesson_6/6-4.py @@ -0,0 +1,77 @@ +class Car: + def __init__(self, speed, color, name, is_police): + self.speed = speed + self.color = color + self.name = name + self.is_police = is_police + + def go(self): + return f'{self.name} is started' + + def stop(self): + return f'{self.name} is stopped' + + def turn_right(self): + return f'{self.name} is turned right' + + def turn_left(self): + return f'{self.name} is turned left' + + def show_speed(self): + return f'Current speed {self.name} is {self.speed}' + + +class TownCar(Car): + def __init__(self, speed, color, name, is_police): + super().__init__(speed, color, name, is_police) + + def show_speed(self): + print(f'Current speed of town car {self.name} is {self.speed}') + + if self.speed > 40: + return f'Speed of {self.name} is higher than allow for town car' + else: + return f'Speed of {self.name} is normal for town car' + + +class SportCar(Car): + def __init__(self, speed, color, name, is_police): + super().__init__(speed, color, name, is_police) + + +class WorkCar(Car): + def __init__(self, speed, color, name, is_police): + super().__init__(speed, color, name, is_police) + + def show_speed(self): + print(f'Speed of work car {self.name} is {self.speed}') + + if self.speed > 60: + return f'Speed of {self.name} is higher than allow for work car' + + +class PoliceCar(Car): + def __init__(self, speed, color, name, is_police): + super().__init__(speed, color, name, is_police) + + def police(self): + if self.is_police: + return f'{self.name} is from police department' + else: + return f'{self.name} is not from police department' + + +mazda = SportCar(100, 'Red', 'Mazda', False) +toyota = TownCar(30, 'Grey', 'Toyota', False) +vw = WorkCar(70, 'White', 'VW', False) +dodge = PoliceCar(110, 'Black', 'Dodge', True) +print(vw.turn_left()) +print(f'When {toyota.turn_right()}, then {mazda.stop()}') +print(f'{vw.go()} with speed exactly {vw.show_speed()}') +print(f'{vw.name} is {vw.color}') +print(f'Is {mazda.name} a police car? {mazda.is_police}') +print(f'Is {vw.name} a police car? {vw.is_police}') +print(mazda.show_speed()) +print(toyota.show_speed()) +print(dodge.police()) +print(dodge.show_speed()) \ No newline at end of file diff --git a/lesson_6/6-5.py b/lesson_6/6-5.py new file mode 100644 index 0000000..13739a1 --- /dev/null +++ b/lesson_6/6-5.py @@ -0,0 +1,38 @@ +class Stationary: + def __init__(self, title): + self.title = title + + def draw(self): + return f'Запуск отрисовки {self.title}' + + +class Pen(Stationary): + def __init__(self, title): + super().__init__(title) + + def draw(self): + return f'Вы взяли {self.title}. Запуск отрисовки ручкой' + + +class Pencil(Stationary): + def __init__(self, title): + super().__init__(title) + + def draw(self): + return f'Вы взяли {self.title}. Запуск отрисовки карандашом' + + +class Handle(Stationary): + def __init__(self, title): + super().__init__(title) + + def draw(self): + return f'Вы взяли {self.title}. Запуск отрисовки маркером' + + +pen = Pen('Ручка') +pencil = Pencil('Карандаш') +handle = Handle('Маркер') +print(pen.draw()) +print(pencil.draw()) +print(handle.draw()) \ No newline at end of file