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
32 changes: 32 additions & 0 deletions lesson_6/6-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from time import sleep


def out_red(text):
print("\033[31m {}".format(text))


def out_yellow(text):
print("\033[33m {}".format(text))


def out_green(text):
print("\033[32m {}".format(text))


class TrafficLight:
__color = ['red', 'green', 'yellow']

def running (self):
while True:
out_red('RED')
sleep(7)
out_yellow('YELLOW')
sleep(2)
out_green('GREEN')
sleep(7)
out_yellow('YELLOW')
sleep(2)


TrafficLight = TrafficLight()
TrafficLight.running()
12 changes: 12 additions & 0 deletions lesson_6/6-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Road:
def __init__(self, length, width):
self._length = length
self._width = width

def profit(self, weight=25, thickness=5):
return f'{self._length} m * {self._width} m * {weight} kg * {thickness} sm =' \
f'{(self._length * self._width * weight * thickness) / 1000} t'


road_1 = Road(5000, 20)
print(road_1.profit())
25 changes: 25 additions & 0 deletions lesson_6/6-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Worker:

def __init__(self, name, surname, position, wage, bonus):
self.name = name
self.surname = surname
self.position = position
self._income = {"wage": wage, "bonus": bonus}


class Position(Worker):

def __init__(self, name, surname, position, wage, bonus):
super().__init__(name, surname, position, wage, bonus)

def get_full_name(self):
return self.name + ' ' + self.surname

def get_total_income(self):
return self._income.get('wage') + self._income.get('bonus')


a = Position('John', 'Johnson', 'Programmer', 100000, 40000)
print(a.get_full_name())
print(a.position)
print(a.get_total_income())
77 changes: 77 additions & 0 deletions lesson_6/6-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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):
return f'{self.name} is started'

def stop(self):
return f'{self.name} is stopped'

def turn_right(self):
return f'{self.name} is turned right'

def turn_left(self):
return f'{self.name} is turned left'

def show_speed(self):
return f'Current speed {self.name} is {self.speed}'


class TownCar(Car):
def __init__(self, speed, color, name, is_police):
super().__init__(speed, color, name, is_police)

def show_speed(self):
print(f'Current speed of town car {self.name} is {self.speed}')

if self.speed > 40:
return f'Speed of {self.name} is higher than allow for town car'
else:
return f'Speed of {self.name} is normal for town car'


class SportCar(Car):
def __init__(self, speed, color, name, is_police):
super().__init__(speed, color, name, is_police)


class WorkCar(Car):
def __init__(self, speed, color, name, is_police):
super().__init__(speed, color, name, is_police)

def show_speed(self):
print(f'Speed of work car {self.name} is {self.speed}')

if self.speed > 60:
return f'Speed of {self.name} is higher than allow for work car'


class PoliceCar(Car):
def __init__(self, speed, color, name, is_police):
super().__init__(speed, color, name, is_police)

def police(self):
if self.is_police:
return f'{self.name} is from police department'
else:
return f'{self.name} is not from police department'


mazda = SportCar(100, 'Red', 'Mazda', False)
toyota = TownCar(30, 'Grey', 'Toyota', False)
vw = WorkCar(70, 'White', 'VW', False)
dodge = PoliceCar(110, 'Black', 'Dodge', True)
print(vw.turn_left())
print(f'When {toyota.turn_right()}, then {mazda.stop()}')
print(f'{vw.go()} with speed exactly {vw.show_speed()}')
print(f'{vw.name} is {vw.color}')
print(f'Is {mazda.name} a police car? {mazda.is_police}')
print(f'Is {vw.name} a police car? {vw.is_police}')
print(mazda.show_speed())
print(toyota.show_speed())
print(dodge.police())
print(dodge.show_speed())
38 changes: 38 additions & 0 deletions lesson_6/6-5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Stationary:
def __init__(self, title):
self.title = title

def draw(self):
return f'Запуск отрисовки {self.title}'


class Pen(Stationary):
def __init__(self, title):
super().__init__(title)

def draw(self):
return f'Вы взяли {self.title}. Запуск отрисовки ручкой'


class Pencil(Stationary):
def __init__(self, title):
super().__init__(title)

def draw(self):
return f'Вы взяли {self.title}. Запуск отрисовки карандашом'


class Handle(Stationary):
def __init__(self, title):
super().__init__(title)

def draw(self):
return f'Вы взяли {self.title}. Запуск отрисовки маркером'


pen = Pen('Ручка')
pencil = Pencil('Карандаш')
handle = Handle('Маркер')
print(pen.draw())
print(pencil.draw())
print(handle.draw())