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
43 changes: 43 additions & 0 deletions task_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

import time
from itertools import cycle

class TrafficLight:
__modes = (('red', 7), ('yellow', 2), ('green', 5), ('yellow', 2))
__light_start = 0
__next_light = 0

def __init__(self):
self.__color = self.__modes[0][0]
self.__tic()

def running(self):

prew_color = None
while True:
self.__tic()
if prew_color != self.__color:
prew_color = self.__color
print(self.__color)

def __tic(self):

if self.__light_start + dict(self.__modes)[self.__color] <= time.time():
self.__color, self.__light_start = self.__modes[self.__next_light][0], time.time()
self.__next_light = self.__next_light + 1 if len(self.__modes) > self.__next_light + 1 else 0

def color(self):
self.__tic()
return self.__color


if __name__ == '__main__':
lighter = TrafficLight()
time.sleep(0.5)
lighter2 = TrafficLight()
time.sleep(0.5)
lighter3 = TrafficLight()
time.sleep(0.5)
for light in cycle((lighter, lighter2, lighter3)):
print(light.color())
time.sleep(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

14 changes: 14 additions & 0 deletions task_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

class Road:
__asphalt_mass = 25

def __init__(self, length, width):
self._length = float(length)
self._width = float(width)

def asphalt_sum(self, thickness=1):
return self._length * self._width * self.__asphalt_mass * thickness

road = Road(20, 5000)
calculation = road.asphalt_sum(5)
print(calculation)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено

22 changes: 22 additions & 0 deletions task_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

class Worker:
name: str
surname: str
position: str
_income: dict

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 get_full_name(self):
return f'{self.name} {self.surname}'

def get_total_income(self):
return sum(self._income.values())

first_person = Position ( 'Анатолий', 'Иванов','Менеджер', 12000, 1000)
print(first_person.get_full_name(), first_person.get_total_income())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

выполнено