From 13fec74032390728773e1e54cf40dd179ab82749 Mon Sep 17 00:00:00 2001 From: azateyka Date: Tue, 17 Jan 2023 21:40:58 +0500 Subject: [PATCH] Homework 6 --- task_1.py | 43 +++++++++++++++++++++++++++++++++++++++++++ task_2.py | 14 ++++++++++++++ task_3.py | 22 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 task_1.py create mode 100644 task_2.py create mode 100644 task_3.py diff --git a/task_1.py b/task_1.py new file mode 100644 index 0000000..b904628 --- /dev/null +++ b/task_1.py @@ -0,0 +1,43 @@ + +import time +from itertools import cycle + +class TrafficLight: + __modes = (('red', 7), ('yellow', 2), ('green', 5), ('yellow', 2)) + __light_start = 0 + __next_light = 0 + + def __init__(self): + self.__color = self.__modes[0][0] + self.__tic() + + def running(self): + + prew_color = None + while True: + self.__tic() + if prew_color != self.__color: + prew_color = self.__color + print(self.__color) + + def __tic(self): + + if self.__light_start + dict(self.__modes)[self.__color] <= time.time(): + self.__color, self.__light_start = self.__modes[self.__next_light][0], time.time() + self.__next_light = self.__next_light + 1 if len(self.__modes) > self.__next_light + 1 else 0 + + def color(self): + self.__tic() + return self.__color + + +if __name__ == '__main__': + lighter = TrafficLight() + time.sleep(0.5) + lighter2 = TrafficLight() + time.sleep(0.5) + lighter3 = TrafficLight() + time.sleep(0.5) + for light in cycle((lighter, lighter2, lighter3)): + print(light.color()) + time.sleep(1) diff --git a/task_2.py b/task_2.py new file mode 100644 index 0000000..d22352e --- /dev/null +++ b/task_2.py @@ -0,0 +1,14 @@ + +class Road: + __asphalt_mass = 25 + + def __init__(self, length, width): + self._length = float(length) + self._width = float(width) + + def asphalt_sum(self, thickness=1): + return self._length * self._width * self.__asphalt_mass * thickness + +road = Road(20, 5000) +calculation = road.asphalt_sum(5) +print(calculation) \ No newline at end of file diff --git a/task_3.py b/task_3.py new file mode 100644 index 0000000..6cc31e1 --- /dev/null +++ b/task_3.py @@ -0,0 +1,22 @@ + +class Worker: + name: str + surname: str + position: str + _income: dict + + 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 get_full_name(self): + return f'{self.name} {self.surname}' + + def get_total_income(self): + return sum(self._income.values()) + +first_person = Position ( 'Анатолий', 'Иванов','Менеджер', 12000, 1000) +print(first_person.get_full_name(), first_person.get_total_income())