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 hometask6/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# nevl 2021

import time

class TrafficLight:
__color = 'red'

def running(self):
print('TrafficLight running')
for _ in range(10):
if self.__color == 'red':
for i in range(7, 0, -1):
print(f'\rred (7): {i}', end='')
time.sleep(1)
self.__color = 'yellow'
elif self.__color == 'yellow':
for i in range(2, 0, -1):
print(f'\ryellow (2): {i}', end='')
time.sleep(1)
self.__color = 'green'
elif self.__color == 'green':
for i in range(10, 0, -1):
print(f'\rgreen (10): {i}', end='')
time.sleep(1)
self.__color = 'red'
print('TrafficLight stop')


if __name__ == '__main__':
tf = TrafficLight()
tf.running()
18 changes: 18 additions & 0 deletions hometask6/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# nevl 2021

class Road:
__length = 0.0
__width = 0.0

def __init__(self, length, width):
self.__length = length
self.__width = width

def calc(self, depth=1):
return self.__length * self.__width * 25 * depth / 1000.0
Comment on lines +12 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

массу и толщину нужно было передавать как параметры



if __name__ == '__main__':
road = Road(5000, 20)
print(road.calc(5))
33 changes: 33 additions & 0 deletions hometask6/task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# nevl 2021

class Worker:
name = ''
surname = ''
position = ''
__income = {"wage": 0, "bonus": 0}

def __init__(self, name, surname, position, wage, bonus):
self.name = name
self.surname = surname
self.position = position
self.__income['wage'] = wage
self.__income['bonus'] = bonus

def get_income(self):
return self.__income


class Position(Worker):
def get_full_name(self):
return f'{self.name} {self.surname} {self.position}'

def get_total_income(self):
income = self.get_income()
return income['wage'] + income['bonus']


if __name__ == '__main__':
pos = Position('John', 'Doe', 'plumber', 20000, 500)
print(pos.get_full_name())
print(pos.get_total_income())
92 changes: 92 additions & 0 deletions hometask6/task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python
# nevl 2021

import random

class Car:
speed = 0
color = ''
name = ''
is_police = False

def __init__(self, color, name, is_police=False):
self.color = color
self.name = name
self.is_police = is_police

def go(self):
self.speed = random.randint(1, 100)
print(f'Car {self.name} ({self.color}) is going')

def stop(self):
self.speed = 0
print(f'Car {self.name} ({self.color}) is staying')

def turn(self, direction):
if self.speed:
print(f'Car {self.name} ({self.color}) turned to the {direction}')
else:
print(f'Car {self.name} ({self.color}) is staying')

def show_speed(self):
if self.speed <= 0:
print(f'Car {self.name} ({self.color}) is staying. Speed 0 km/h')
print(f'Speed car {self.name} ({self.color}) is {self.speed} km/h')


class TownCar(Car):
def show_speed(self):
super().show_speed()
if self.speed > 60:
print('Over speed ')


class SportCar(Car):
pass


class WorkCar(Car):
def show_speed(self):
super().show_speed()
if self.speed > 40:
print('Over speed ')


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


if __name__ == '__main__':
tc = TownCar('red', 'Mazda')
tc.go()
tc.show_speed()
tc.turn('right')
tc.stop()
tc.show_speed()
print('-' * 30)

sc = SportCar('blue', 'Nissan GTR')
sc.go()
sc.show_speed()
sc.turn('left')
sc.stop()
sc.show_speed()
print('-' * 30)

wc = WorkCar('grey', 'MAZ')
wc.go()
wc.show_speed()
wc.turn('left')
wc.stop()
wc.show_speed()
print('-' * 30)


pc = PoliceCar('white', 'Mercedes')
pc.go()
pc.show_speed()
pc.turn('left')
pc.stop()
pc.show_speed()
print('-' * 30)
46 changes: 46 additions & 0 deletions hometask6/task5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# nevl 2021

class Stationery:
title = ''

def __init__(self, title):
self.title = title

def draw(self):
print('Drawing start')


class Pen(Stationery):
def __init__(self, title='Pen'):
super().__init__(title)

def draw(self):
print(f'Drawing super puper pen: {self.title}')


class Pencil(Stationery):
def __init__(self, title='Pencil'):
super().__init__(title)

def draw(self):
print(f'Pencil is a very important thing: {self.title}')


class Handle(Stationery):
def __init__(self, title='Handle'):
super().__init__(title)

def draw(self):
print(f'Handle is permanent marker: {self.title}')


if __name__ == '__main__':
pen = Pen()
pen.draw()

pencil = Pencil()
pencil.draw()

handle = Handle()
handle.draw()