Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Lesson_6/dz_1.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions Lesson_6/dz_2.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions Lesson_6/dz_3.py
Original file line number Diff line number Diff line change
@@ -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())
60 changes: 60 additions & 0 deletions Lesson_6/dz_4.py
Original file line number Diff line number Diff line change
@@ -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()
31 changes: 31 additions & 0 deletions Lesson_6/dz_5.py
Original file line number Diff line number Diff line change
@@ -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()