diff --git a/task1.py b/task1.py new file mode 100644 index 0000000..a4c9931 --- /dev/null +++ b/task1.py @@ -0,0 +1,20 @@ +import time + +class TrafficLight: + def running(self): + while True: + self.__color = 'красный' + self.status() + time.sleep(7) + self.__color = 'желтый' + self.status() + time.sleep(2) + self.__color = 'зеленый' + self.status() + time.sleep(10) + + def status(self): + print(f'Сейчас горит {self.__color}') + +traffic_light = TrafficLight() +traffic_light.running() diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..fb0caa1 --- /dev/null +++ b/task2.py @@ -0,0 +1,17 @@ +class Road: + weight = 25 # кг асфальта, для покрытия 1 кв. метра полотна + + def __init__(self, width, length): + self._width = width + self._length = length + + def calc(self, weight, depth): + return self._length * self._width * self.weight * depth + +width = 20 # ширина полотна +length = 5000 # длинна дороги в метрах +road_1 = Road(width, length) + +depth = 5 # см толщины полотна +print(f'масса асфальта для покрытия {depth} см полотна, длинной {round(length/1000, 2)} км,' + f'и шириной {width} м - {round(road_1.calc(25, 5) / 1000, 3)} т.') \ No newline at end of file diff --git a/task3.py b/task3.py new file mode 100644 index 0000000..604fa94 --- /dev/null +++ b/task3.py @@ -0,0 +1,21 @@ +class Worker: + + def __init__(self, name, surname, position, _income): + self.name = name + self.surname = surname + self.position = position + self._income = _income + + +class Position(Worker): + + def get_full_name(self): + return self.name + ' ' + self.surname + + def get_total_income(self): + return int(self._income['wage']) + int(self._income['bonus']) + + +man_1 = Position('Вася', 'Пупкин', 'Бухгалтер', {'wage': 100, 'bonus': 50}) +print(f'Сотрудника зовут - {man_1.get_full_name()}!') +print(f'Он получает - {man_1.get_total_income()}тр в месяц') diff --git a/task4.py b/task4.py new file mode 100644 index 0000000..7a2d839 --- /dev/null +++ b/task4.py @@ -0,0 +1,58 @@ +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): + print('Машина поехала') + + def stop(self): + print('Машина остановилась') + + def tern(self, direction): + print(f'Машина повернула {direction}') + + def show_speed(self): + print(self.speed) + + +class TownCar(Car): + + def show_speed(self): + if (int(self.speed) > 60): + print('Превышена скорость!') + Car.show_speed(self) + + +class SportCar(Car): + pass + + +class WorkCar(Car): + def show_speed(self): + if (int(self.speed) > 60): + print('Превышена скорость!') + Car.show_speed(self) + + +class PoliceCar(Car): + + def __init__(self, *args): + Car.__init__(self, *args) + self.is_police = True + + +car1 = TownCar(35, 'red', 'lada', False) +car1.go() +car1.show_speed() +car2 = TownCar(75, 'white', 'kia', False) +car2.show_speed() +car3 = WorkCar(35, 'black', 'maz', False) +car3.show_speed() +car4 = SportCar(135, 'red', 'ferarry', False) +car4.show_speed() +car5 = PoliceCar(125, 'blue', 'policy', True) +car5.show_speed() diff --git a/task5.py b/task5.py new file mode 100644 index 0000000..2e6b5ea --- /dev/null +++ b/task5.py @@ -0,0 +1,29 @@ +class Stationery: + + def __init__(self, title): + self.title = title + + def draw(self): + print('Запуск отрисовки.') + + +class Pen(Stationery): + def draw(self): + Stationery.draw(self) + print(f'{self.title} рисует круг!') + + +class Pencil(Stationery): + def draw(self): + Stationery.draw(self) + print(f'{self.title} рисует квадрат!') + + +class Handle(Stationery): + def draw(self): + Stationery.draw(self) + print(f'{self.title} рисует треугольник!') + +pen = Pen('Ручка').draw() +pen = Pencil('Карандаш').draw() +pen = Handle('Маркер').draw() \ No newline at end of file