diff --git a/Lesson_6/dz_1.py b/Lesson_6/dz_1.py new file mode 100644 index 0000000..233db73 --- /dev/null +++ b/Lesson_6/dz_1.py @@ -0,0 +1,34 @@ +import time +import itertools + + +# class TrafficLight: +# __color = 'nomatter' +# +# def running(self): +# while True: +# print('Red') +# time.sleep(6) +# print('Yellow') +# time.sleep(2) +# print('Green') +# time.sleep(6) +# print('Yellow') +# time.sleep(2) +# +# +# trafficl = TrafficLight() +# trafficl.running() + + +class TrafficLight: + __color = [['red', [6, 31]], ['yellow', [2, 33]], ['green', [6, 32]], ['yellow', [2, 33]]] + + def runnig(self): + for light in itertools.cycle(self.__color): + print(f"\r\033[{light[1][1]}m\033[1m{light[0]}\033[0m", end='') + time.sleep(light[1][0]) + + +trafficl = TrafficLight() +trafficl.runnig() diff --git a/Lesson_6/dz_2.py b/Lesson_6/dz_2.py new file mode 100644 index 0000000..1b0204b --- /dev/null +++ b/Lesson_6/dz_2.py @@ -0,0 +1,11 @@ +class RoadCount: + def __init__(self, le, wi): + self._length = le + self._width = wi + + def count(self, weight=25, thickness=5): + print(f"Необходимо {self._length * self._width * weight * thickness / 1000:0.0f} тонн асфальта") + + +my_road = RoadCount(int(input('Введите ширину дороги в метрах: ')), int(input('Введите длину дороги в метрах: '))) +my_road.count() diff --git a/Lesson_6/dz_3.py b/Lesson_6/dz_3.py new file mode 100644 index 0000000..032a695 --- /dev/null +++ b/Lesson_6/dz_3.py @@ -0,0 +1,20 @@ +class Worker: + def __init__(self, name, surname, position, wage, bonus): + self.name = name + self.surname = surname + self.position = position + self._incom = {'profit': 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._incom.values()) + + +driver = Position('Mike', 'Smith', 'Driver', 3500, 750) +print(driver.get_full_name()) +print(driver.position) +print(driver.get_total_income()) diff --git a/Lesson_6/dz_4.py b/Lesson_6/dz_4.py new file mode 100644 index 0000000..b4aba82 --- /dev/null +++ b/Lesson_6/dz_4.py @@ -0,0 +1,60 @@ +from random import choice + + +class Car: + direction = ['left', 'right'] + + def __init__(self, n, c, s, p=False): + self.name = n + self.color = c + self.speed = s + self.is_police = p + print(f'Ваша машина: {n}, цвет: {c}.\nЭто полицейский автомобиль? {p}') + + def go(self): + print(f'{self.name}: Машина поехала.') + + def stop(self): + print(f'{self.name}: Машина остановилась.') + + def turn(self): + print(f'{self.name}: Машина повернула {choice(self.direction)}.') + + def show_speed(self): + print(f'{self.name}: Скорость машины: {self.speed}') + + +class TownCar(Car): + def show_speed(self): + return f'{self.name}: Скорость машины: {self.speed}, так быстро нельзя!'\ + if self.speed > 60 else super().show_speed() + + +class SportCar(Car): + """ Sport Car """ + + +class WorkCar(Car): + def show_speed(self): + return f'{self.name}: Скорость машины: {self.speed}, так быстро нельзя!' \ + if self.speed > 40 else super().show_speed() + + +class PoliceCar(Car): + def __init__(self, n, c, s): + super().__init__(n, c, s, p=True) + + +town = TownCar('Honda Fit', 'Синий', 75) +sport = SportCar('Nissan TG-R', 'Белый', 180) +work = WorkCar('Dodge Ram', 'Красный', 40) +police = PoliceCar('Ford Mondeo', 'Синий', 90) + +all_cars = [town, sport, work, police] + +for i in all_cars: + i.go() + print(i.show_speed()) + i.turn() + i.stop() + print() diff --git a/Lesson_6/dz_5.py b/Lesson_6/dz_5.py new file mode 100644 index 0000000..ff009fb --- /dev/null +++ b/Lesson_6/dz_5.py @@ -0,0 +1,31 @@ +class Stationery: + def __init__(self, title="Канцелярия"): + self.title = title + + def draw(self): + print(f'{self.title} поможет тебе творить') + + +class Pen(Stationery): + def draw(self): + print(f'Ручкой лучше всего {self.title}') + + +class Pencil(Stationery): + def draw(self): + print(f'Карандашом удобно {self.title}') + + +class Marker(Stationery): + def draw(self): + print(f'Маркером можно {self.title}') + +stationery = Stationery() +pen = Pen('писать') +pencil = Pencil('чертить') +marker = Marker('рисовать') + +my_stationery = [stationery, pen, pencil, marker] + +for i in my_stationery: + i.draw()