From 9cd2e1b28d809871b227a30caf60d10f0b3b6c16 Mon Sep 17 00:00:00 2001 From: dkyopwa Date: Sun, 24 Oct 2021 22:55:30 +0300 Subject: [PATCH] Added hometask 6 --- hometask6/task1.py | 32 ++++++++++++++++ hometask6/task2.py | 18 +++++++++ hometask6/task3.py | 33 +++++++++++++++++ hometask6/task4.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++ hometask6/task5.py | 46 +++++++++++++++++++++++ 5 files changed, 221 insertions(+) create mode 100644 hometask6/task1.py create mode 100644 hometask6/task2.py create mode 100644 hometask6/task3.py create mode 100644 hometask6/task4.py create mode 100644 hometask6/task5.py diff --git a/hometask6/task1.py b/hometask6/task1.py new file mode 100644 index 0000000..1e2b015 --- /dev/null +++ b/hometask6/task1.py @@ -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() diff --git a/hometask6/task2.py b/hometask6/task2.py new file mode 100644 index 0000000..dd572b1 --- /dev/null +++ b/hometask6/task2.py @@ -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 + + +if __name__ == '__main__': + road = Road(5000, 20) + print(road.calc(5)) diff --git a/hometask6/task3.py b/hometask6/task3.py new file mode 100644 index 0000000..98d7b8d --- /dev/null +++ b/hometask6/task3.py @@ -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()) diff --git a/hometask6/task4.py b/hometask6/task4.py new file mode 100644 index 0000000..0952ae6 --- /dev/null +++ b/hometask6/task4.py @@ -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) diff --git a/hometask6/task5.py b/hometask6/task5.py new file mode 100644 index 0000000..7f25d43 --- /dev/null +++ b/hometask6/task5.py @@ -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()