From 0b330fc061d4ec365e813373f1bfa735fcb193cf Mon Sep 17 00:00:00 2001 From: alardis Date: Thu, 24 Oct 2019 22:18:39 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D1=8B?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B8=D1=85=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_6/hw01_6.py | 6 ++++++ lesson_6/hw02_6.py | 9 +++++++++ lesson_6/hw03_6.py | 8 ++++++++ lesson_6/hw04_6.py | 5 +++++ lesson_6/hw05_6.py | 7 +++++++ 5 files changed, 35 insertions(+) create mode 100644 lesson_6/hw01_6.py create mode 100644 lesson_6/hw02_6.py create mode 100644 lesson_6/hw03_6.py create mode 100644 lesson_6/hw04_6.py create mode 100644 lesson_6/hw05_6.py diff --git a/lesson_6/hw01_6.py b/lesson_6/hw01_6.py new file mode 100644 index 0000000..f8830d8 --- /dev/null +++ b/lesson_6/hw01_6.py @@ -0,0 +1,6 @@ +# Создать класс TrafficLight (светофор) и определить у него один атрибут color (цвет) и метод running (запуск). +# Атрибут реализовать как приватный. В рамках метода реализовать переключение светофора в режимы: красный, желтый, +# зеленый. Время перехода между режимами должно составлять 7 и 2 секунды. +# Проверить работу примера, создав экземпляр и вызвав описанный метод. + + diff --git a/lesson_6/hw02_6.py b/lesson_6/hw02_6.py new file mode 100644 index 0000000..1444c7a --- /dev/null +++ b/lesson_6/hw02_6.py @@ -0,0 +1,9 @@ +# Реализовать класс Road (дорога), в котором определить атрибуты: length (длина), width (ширина). +# Значения данных атрибутов должны передаваться при создании экземпляра класса. Атрибуты сделать защищенными. +# Определить метод расчета массы асфальта, необходимого для покрытия всего дорожного полотна. +# Использовать формулу: длина*ширина*масса асфальта для покрытия одного кв метра дороги асфальтом, +# толщиной в 1 см*число см толщины полотна. Проверить работу метода. +# Например: 20м*5000м*25кг*5см = 12500 т + + + diff --git a/lesson_6/hw03_6.py b/lesson_6/hw03_6.py new file mode 100644 index 0000000..eab9a52 --- /dev/null +++ b/lesson_6/hw03_6.py @@ -0,0 +1,8 @@ +# Реализовать базовый класс Worker (работник), в котором определить атрибуты: name, surname, position (должность), +# income (доход). Последний атрибут должен быть защищенным и ссылаться на словарь, содержащий элементы: оклад и премия, +# например, {"profit": profit, "bonus": bonus}. Создать класс Position (должность) на базе класса Worker. +# В классе Position реализовать методы получения полного имени сотрудника (get_full_name) и дохода с учетом премии +# (get_full_profit). Проверить работу примера на реальных данных (создать экземпляры класса Position, +# передать данные, проверить значения атрибутов, вызвать методы экземпляров). + + diff --git a/lesson_6/hw04_6.py b/lesson_6/hw04_6.py new file mode 100644 index 0000000..f90e484 --- /dev/null +++ b/lesson_6/hw04_6.py @@ -0,0 +1,5 @@ +# Опишите несколько классов: TownCar, SportCar, WorkCar, PoliceCar. У каждого класса должны быть следующие атрибуты: +# speed, color, name, is_police (булево). А также несколько методов: go, stop, turn(direction), которые должны +# сообщать, что машина поехала, остановилась, повернула (куда). + + diff --git a/lesson_6/hw05_6.py b/lesson_6/hw05_6.py new file mode 100644 index 0000000..8ec5c10 --- /dev/null +++ b/lesson_6/hw05_6.py @@ -0,0 +1,7 @@ +# Реализовать класс Stationery (канцелярская принадлежность). Определить в нем атрибут title (название) и метод draw +# (отрисовка). Метод выводит сообщение “Запуск отрисовки.” Создать три дочерних класса Pen (ручка), Pencil (карандаш), +# Handle (маркер). В каждом из классов реализовать переопределение метода draw. Для каждого из классов методы должен +# выводить уникальное сообщение. Создать экземпляры классов и проверить, что выведет описанный метод +# для каждого экземпляра. + + From 9b70d17f528c0256fa616fee62e25bfa181dff20 Mon Sep 17 00:00:00 2001 From: "VIZEX\\ashumov" Date: Fri, 25 Oct 2019 11:15:39 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_6/hw01_6.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lesson_6/hw01_6.py b/lesson_6/hw01_6.py index f8830d8..99888c0 100644 --- a/lesson_6/hw01_6.py +++ b/lesson_6/hw01_6.py @@ -4,3 +4,30 @@ # Проверить работу примера, создав экземпляр и вызвав описанный метод. +import time + +class TrafficLight: + __color = None + + def running(self): + time_to_start = time.time() + current_time = None + __color = 'красный' + print(f'Режим светофора: {__color}') + + while __color != 'зеленый': + current_time = time.time() + if current_time - time_to_start == 1: + print(time.time()) + + if current_time - time_to_start >= 7 and __color == 'красный': + __color = 'желтый' + print(f'Режим светофора: {__color}') + time_to_start = time.time() + elif current_time - time_to_start >= 2 and __color == 'желтый': + __color = 'зеленый' + print(f'Режим светофора: {__color}') + + +light = TrafficLight() +light.running() From 52294033a0e9e12bf42b2d419f074a49624f746c Mon Sep 17 00:00:00 2001 From: "VIZEX\\ashumov" Date: Fri, 25 Oct 2019 11:36:15 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_6/hw02_6.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lesson_6/hw02_6.py b/lesson_6/hw02_6.py index 1444c7a..dcbea60 100644 --- a/lesson_6/hw02_6.py +++ b/lesson_6/hw02_6.py @@ -5,5 +5,21 @@ # толщиной в 1 см*число см толщины полотна. Проверить работу метода. # Например: 20м*5000м*25кг*5см = 12500 т +# замечу, что формула в примере расчета некорректная, поскольку 5см необходимо перевести в метры, что мы и сделаем +class Road: + _length: int + _width: int + + def __init__(self, length, width): + self._length = length + self._width = width + + def get_quantity(self, thickness): + quantity = self._length * self._width * 25 * thickness / 1000 + print(f'Масса асфальта: {self._length}м * {self._width}м * 25кг * {thickness}м = {quantity} тонн') + + +road = Road(5000, 20) +road.get_quantity(0.05) From 9d59a64a532266286ffd8220793de4045c17c7e6 Mon Sep 17 00:00:00 2001 From: "VIZEX\\ashumov" Date: Mon, 28 Oct 2019 10:19:39 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9F=D1=8F=D1=82=D0=B0=D1=8F=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_6/hw05_6.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lesson_6/hw05_6.py b/lesson_6/hw05_6.py index 8ec5c10..72d8f87 100644 --- a/lesson_6/hw05_6.py +++ b/lesson_6/hw05_6.py @@ -5,3 +5,33 @@ # для каждого экземпляра. +class Stationery: + title: str + + def draw(self): + print('Запуск отрисовки') + + +class Pen(Stationery): + def draw(self): + print('Пишем ручкой. Ластиком не стирается :(') + + +class Pencil(Stationery): + def draw(self): + print('Пишем карандашом. Надо бы заточить!') + + +class Handle(Stationery): + def draw(self): + print('Пишем маркером. Очень толстая линия, стирается хуже ручки') + + +pen = Pen() +pen.draw() + +pencil = Pencil() +pencil.draw() + +handle = Handle() +handle.draw() From 3787b83b95aba5f2242540bfd40b46af10db76bf Mon Sep 17 00:00:00 2001 From: "VIZEX\\ashumov" Date: Mon, 28 Oct 2019 10:57:25 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A7=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_6/hw04_6.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/lesson_6/hw04_6.py b/lesson_6/hw04_6.py index f90e484..7fce106 100644 --- a/lesson_6/hw04_6.py +++ b/lesson_6/hw04_6.py @@ -3,3 +3,64 @@ # сообщать, что машина поехала, остановилась, повернула (куда). +class Car: + speed: int + color: int + name: int + is_police: bool + + 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): + print(f'Машина поехала со скоростью {self.speed}') + + def stop(self): + print('Машина остановилась') + + def turn(self, direction:str): + print(f'Машина поворачивает {direction}') + + +class TownCar(Car): + + def __init__(self, speed, color, name, is_police=False): + super().__init__(speed, color, name, is_police) + + +class SportCar(Car): + + def __init__(self, speed, color, name, is_police=False): + super().__init__(speed, color, name, is_police) + + +class WorkCar(Car): + + def __init__(self, speed, color, name, is_police=False): + super().__init__(speed, color, name, is_police) + + +class PoliceCar(Car): + + def __init__(self, speed, color, name, is_police=True): + super().__init__(speed, color, name, is_police) + + +towncar = TownCar(300, 'Красный', 'Мазератти') +towncar.go() +print(type(towncar)) + +sportcar = SportCar(400, 'Белый', 'Феррари') +sportcar.stop() +print(type(sportcar)) + +workcar = WorkCar(120, 'Синий', 'Киа') +workcar.turn('направо') +print(type(sportcar)) + +policecar = PoliceCar(400, 'Бело-синий', 'Додж') +policecar.go() +print(type(policecar)) From 383df23b217b0df4e88107aa3e26abdba200dc3c Mon Sep 17 00:00:00 2001 From: "VIZEX\\ashumov" Date: Mon, 28 Oct 2019 16:11:22 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_6/hw03_6.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lesson_6/hw03_6.py b/lesson_6/hw03_6.py index eab9a52..d133793 100644 --- a/lesson_6/hw03_6.py +++ b/lesson_6/hw03_6.py @@ -6,3 +6,34 @@ # передать данные, проверить значения атрибутов, вызвать методы экземпляров). +class Worker: + name: str + surname: str + position: str + _income: dict + + def __init__(self, name, surname, position, profit, bonus): + self.name = name + self.surname = surname + self.position = position + self._income = {'profit': profit, 'bonus': bonus} + + +class Position(Worker): + + def __init__(self, name, surname, position, profit, bonus): + super().__init__(name, surname, position, profit, bonus) + + def get_full_name(self): + print(f'Полное имя сотрудника: {self.name} {self.surname}') + + def get_full_profit(self): + full_profit = 0 + for key, value in self._income.items(): + full_profit += value + print(f'Доход с учетом премии: {full_profit}') + + +position_test = Position('Андрей', 'Иванов', 'менеджер', 400, 100) +position_test.get_full_name() +position_test.get_full_profit()