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 1.py
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions 2.py
Original file line number Diff line number Diff line change
@@ -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())
26 changes: 26 additions & 0 deletions 3.py
Original file line number Diff line number Diff line change
@@ -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)
66 changes: 66 additions & 0 deletions 4.py
Original file line number Diff line number Diff line change
@@ -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()
44 changes: 44 additions & 0 deletions 5.py
Original file line number Diff line number Diff line change
@@ -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()