diff --git a/1.py b/1.py new file mode 100644 index 0000000..f4234d7 --- /dev/null +++ b/1.py @@ -0,0 +1,34 @@ +from time import sleep + + +class TrafficLight(): + def __init__(self): + self.__color = 'red' + + def running(self): + '''run TrafficLight and printin color''' + print('start running') + print(self.__color) + sleep(7) + self.new_color() + print(self.__color) + sleep(2) + self.new_color() + print(self.__color) + sleep(5) + print('stop running') + + def new_color(self): + '''check and set color''' + if self.__color == 'red': + self.__color = 'yellow' + elif self.__color == 'yellow': + self.__color = 'green' + elif self.__color == 'green': + self.__color = 'red' + else: + raise ValueError('color error') + + +t = TrafficLight() +t.running() diff --git a/2.py b/2.py new file mode 100644 index 0000000..5668ec1 --- /dev/null +++ b/2.py @@ -0,0 +1,18 @@ +class Road(): + def __init__(self, length, width): + self._length = length + self._width = width + self.bulk = 5 # задать толщину по умолчанию 5 см + self.mass = 0.025 # задать массу в тоннах на 1 см толщины + + def calculation_1_meter(self): + return self.bulk*self.mass + + def сalculation(self): + '''calculation mass asphalt''' + res = self._length * self._width * self.calculation_1_meter() + return res + + +r = Road(5000, 20) +print(r.сalculation()) diff --git a/3.py b/3.py new file mode 100644 index 0000000..3948fe2 --- /dev/null +++ b/3.py @@ -0,0 +1,26 @@ + +class Worker(): + income = {'wage': 100, 'bonus': 20} + + def __init__(self, name, surname, position): + self.name = name + self.surname = surname + self.position = position + + +class Position(Worker): + def __init__(self, name, surname, position): + super().__init__(name, surname, position) + + def get_full_name(self): + print(f'{self.name} {self.surname}') + + def get_total_income(self): + res = self.income['wage']*self.income['bonus'] + print(f' full income {res}') + + +pos = Position('Виктор', 'Петров', 'Програмист') +pos.get_full_name() +pos.get_total_income() +print(pos.income) diff --git a/4.py b/4.py new file mode 100644 index 0000000..2e86eab --- /dev/null +++ b/4.py @@ -0,0 +1,66 @@ +class Car(): + count_cars = 0 + + def __init__(self, color, name, speed, is_police=False): + Car.count_cars += 1 + self.speed = speed + self.color = color + self.name = name + self.is_police = is_police + + def go(self): + print(f'car {self.name} go') + + def stop(self): + print('stop') + + def turn(self, direction): + print(f'car {self.name} turn {direction}') + + def show_speed(self): + print(f'car {self.name} have speed now {speed}') + + def show_count_cars(self): + print(Car.count_cars) + + +class TownCar(Car): + def __init__(self, color, name, speed, is_police=False): + super().__init__(color, name, speed, is_police) + + def show_speed(self): + if self.speed > 60: + print('excess speed!!!!! ', end='') + print(f'speed now {self.speed}') + + +class SportCar(Car): + def __init__(self, color, name, speed, is_police=False): + super().__init__(color, name, speed, is_police) + + +class WorkCar(Car): + def __init__(self, color, name, speed, is_police=False): + super().__init__(color, name, speed, is_police) + + def show_speed(self): + if self.speed > 40: + print('excess speed!!!!!') + print(f'speed now {self.speed}') + + +class PoliceCar(Car): + def __init__(self, color, name, speed): + super().__init__(color, name, speed, is_police=True) + + +sport = SportCar('red', 'bugatti', speed=150) +town = TownCar('grey', 'lada', speed=90) +work = WorkCar('green', 'man', speed=70) +police = PoliceCar('white', 'ford', speed=120) +sport.go() +town.show_speed() +print(police.is_police) + + +town.show_count_cars() diff --git a/5.py b/5.py new file mode 100644 index 0000000..b95e380 --- /dev/null +++ b/5.py @@ -0,0 +1,44 @@ +class Stationery(): + count_stationery = 0 + + def __init__(self, title): + Stationery.count_stationery += 1 + self.title = title + + def draw(self): + print('start draw') + + +class Mod_Stationery(Stationery): # чтобы не перегружать методы в каждом классе добавил мод + def __init__(self, title): + super().__init__(title) + + def draw(self): + print(f'start draw by {self.title}') + + +class Pen(Mod_Stationery): + def __init__(self): + super().__init__('pen') + + def draw(self): + print(f'PEN start draw by {self.title}') # но можно и перегрузить в каждом классе как по заданию + + +class Pencil(Mod_Stationery): + def __init__(self): + super().__init__('pencil') + + +class Handle(Mod_Stationery): + def __init__(self): + super().__init__('handle') + + +pn = Pen() +pl = Pencil() +hl = Handle() + +pn.draw() +pl.draw() +hl.draw()