diff --git a/#1.py b/#1.py new file mode 100644 index 0000000..629ef8f --- /dev/null +++ b/#1.py @@ -0,0 +1,14 @@ +from time import sleep + + +class TrafficLight: + __color = [('красный', 2), ('желтый', 2), ('зеленый', 3)] + + def running(self): + for a, b in self.__color: + print(a) + sleep(b) + + +c = TrafficLight() +c.running() diff --git a/#2.py b/#2.py new file mode 100644 index 0000000..1e26d60 --- /dev/null +++ b/#2.py @@ -0,0 +1,14 @@ +class Road: + def __init__(self, length, width): + self._length = length + self._width = width + + def mass(self, thickness, mass_sm): + return self._length*self._width*thickness*mass_sm + + +Road_1 = Road(20, 5000) +print(Road_1.mass(25, 5)) + + + diff --git a/#3.py b/#3.py new file mode 100644 index 0000000..28fa230 --- /dev/null +++ b/#3.py @@ -0,0 +1,23 @@ +income = {'worker1': {'wage': 10000, 'bonus': 5000}, 'worker2': {'wage': 20000, 'bonus': 5000}} + + +class Worker: + def __init__(self, name, surname, position): + self.name = name + self.surname = surname + self.position = position + self._income = income[position] + + +class Position(Worker): + def get_full_name(self): + print(f'Имя: {self.name}\n' + f'Фамилия: {self.surname}') + + def get_total_income(self): + print(f'Общий доход {self._income["wage"]+self._income["bonus"]}') + + +a = Position("Иван", "Иванов", 'worker1') +a.get_full_name() +a.get_total_income() \ No newline at end of file diff --git a/#4.py b/#4.py new file mode 100644 index 0000000..659085b --- /dev/null +++ b/#4.py @@ -0,0 +1,54 @@ +class Car: + def __init__(self, speed, color, name, is_police=False): + self.speed = speed + self.color = color + self.name = name + self.is_police = is_police + + def go(self, speed=0): + self.speed += speed + if self.speed == 0: + self.speed = int(input('Введите скорость: ')) + print(f'Машина поехала со скоростью {self.speed}') + + def stop(self): + print('Машина остановилась') + self.speed = 0 + + def turn(self, direction): + print(f'Машина повернула в направлении {direction}') + + def show_speed(self): + print(f'Текущая скорость {self.speed}') + + +class TownCar(Car): + def show_speed(self): + print(f'Текущая скорость {self.speed}') + if self.speed > 60: + print('Скорость превышена!') + + +class WorkCar(Car): + def show_speed(self): + print(f'Текущая скорость {self.speed}') + if self.speed > 40: + print('Скорость превышена!') + + +class SportCar(Car): + pass + + +class PoliceCar(Car): + is_police = True + + +TownCar1 = TownCar(61, 'black', 'Tree') +TownCar1.go(10) +TownCar1.show_speed() +print(TownCar1.is_police) +print(TownCar1.color) +TownCar1.stop() +TownCar1.go(30) +TownCar1.show_speed() diff --git a/#5.py b/#5.py new file mode 100644 index 0000000..d35e4dd --- /dev/null +++ b/#5.py @@ -0,0 +1,31 @@ +class Stationery: + def __init__(self, title): + self.title = title + + 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('Запуск отрисовки маркером') + + +a = Stationery('Рисунок1') +a.draw() +b = Pen('Рисунок2') +b.draw() +c = Pencil('Рисунок3') +c.draw() +d = Handle('Рисунок4') +d.draw()