From ae4df5d9d24e2fa045bb517e2a0d5f1f317fe502 Mon Sep 17 00:00:00 2001 From: Filipenko <114gtrap@gmail.com> Date: Tue, 16 May 2023 17:13:02 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..96c32f7 --- /dev/null +++ b/main.py @@ -0,0 +1,33 @@ +def countdown(): + yield from [x for x in range(10, -1, -1)] + + +def eng_alphabet(): + yield from [chr(ch) for ch in range(ord('a'), ord('z')+1)] + + +def fib(limit): + last_num, new_num = 0, 1 + for _ in range(limit): + yield last_num + last_num, new_num = new_num, last_num + new_num + + +def fib_iteration(limit=10): + data = fib(limit=limit) + print("Method 1:", end=" ") + for el in data: + print(el, end=" ") + print("\nMethod 2:", end=" ") + + data = fib(limit) + while True: + print(next(data), end=" ") + + +def even_nums(limit=21): + yield from [num for num in range(limit) if num % 2 == 0] + + +def task6(start=1, limit=24): + return {key: chr(value) for key, value in zip(range(start, limit), range(ord('a'), ord('a') + limit))} From 30d55aabbb8c01129c8f4a0300ef16029ec10bfd Mon Sep 17 00:00:00 2001 From: Filipenko <114gtrap@gmail.com> Date: Tue, 16 May 2023 17:21:15 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=D0=BC=20?= =?UTF-8?q?=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 181 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 159 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 96c32f7..30159be 100644 --- a/main.py +++ b/main.py @@ -1,33 +1,170 @@ -def countdown(): - yield from [x for x in range(10, -1, -1)] +from time import sleep -def eng_alphabet(): - yield from [chr(ch) for ch in range(ord('a'), ord('z')+1)] +class Cat(): + def meow(self): + return "Meow" -def fib(limit): - last_num, new_num = 0, 1 - for _ in range(limit): - yield last_num - last_num, new_num = new_num, last_num + new_num + def purring(self): + return "Pure" + def sleep(self): + return "I'm sleeping" -def fib_iteration(limit=10): - data = fib(limit=limit) - print("Method 1:", end=" ") - for el in data: - print(el, end=" ") - print("\nMethod 2:", end=" ") - data = fib(limit) - while True: - print(next(data), end=" ") +class Good(): + def __init__(self, name, price, weight) -> None: + self.name = name + self.price = price + self.weight = weight + self.calc() + + def calc(self) -> None: + self.cost = self.price * self.weight + + def __str__(self) -> str: + return f"{self.name} costs {self.cost} for {self.weight} KG" + + +class Car(): + color: str + brand: str + body: str + speed: float + transmission: str + restrictions: dict = { + "truck": 60.0, + "sedan": 80.0 + } + + def __init__(self, color: str, brand: str, body: str, speed: float, transmission: str) -> None: + self.color = color.lower() + self.brand = brand.lower() + self.body = body.lower() + self.transmission = transmission + if not self.__check_speed(speed): + self.speed = speed + else: + self.speed = self.restrictions[self.body] + + def start(self) -> str: + return "Это мой последний заезд..." + + def stop(self) -> str: + return "Это был мой последний заезд..." + + def turn(self, side: str) -> str: + return f"Car is turned to the {side}" + + def speed_up(self, value: float) -> str: + new_speed = self.speed + value + if self.__check_speed(new_speed): + return f"Speed hasn't been changed" + + old_speed = self.speed + self.speed += value + return f"Speed has been changed: {old_speed} -> {self.speed}" + + def speed_down(self, value: float) -> str: + old_speed = self.speed + self.speed -= value + return f"Speed has been changed: {old_speed} -> {self.speed}" + + def beep(self) -> str: + return "Союз нерушимый республик свободных....." + + def __check_speed(self, value: float): + restr_speed = self.restrictions[self.body] + if restr_speed < value: + self.speed = restr_speed + print( + f"Скорость превышена! Разрешенная скорость {restr_speed} км/ч. " + + f"Текущая скорость: {self.speed} км/ч") + return True + return False + + -def even_nums(limit=21): - yield from [num for num in range(limit) if num % 2 == 0] +class TrafficLight: + colors: dict + def __init__(self) -> None: + self.colors = { + "green": 2.0, + "yellow": 0.5, + "red": 1.0 + } -def task6(start=1, limit=24): - return {key: chr(value) for key, value in zip(range(start, limit), range(ord('a'), ord('a') + limit))} + def switching(self) -> None: + for i in self.colors: + print(i) + sleep(self.colors[i]) + + +def task1(): + cat = Cat() + cat.name = "Poker" + cat.color = "Black" + cat.age = 3 + print(f"{cat.meow()}\n{cat.purring()}\n{cat.sleep()}") + + +def task2(): + cat = Cat() + cat.name = "Poker" + cat.color = "Black" + cat.age = 3 + print(f"{cat.meow()}\n{cat.purring()}\n{cat.sleep()}") + + apple = Good('apple', price=100, weight=1.5) + pear = Good('pear', price=120, weight=0.8) + print(apple) + print(pear) + + +def task3(): + car = Car("Black", "BMW", "Sedan", 135.0, "I dunno") + print(car.start()) + print(car.turn("left")) + print(car.speed_up(150)) + print(car.speed_down(50)) + print(car.beep()) + print(car.stop()) + print('\n'*2) + + truck = Car("Green", "Samsung", "Truck", 75.0, "Kinda Sorda box") + print(truck.start()) + print(truck.turn("straight")) + print(truck.speed_up(12)) + print(truck.speed_down(12)) + print(truck.beep()) + print(truck.stop()) + + +def task4(): + car = Car("Black", "BMW", "Sedan", 135.0, "I dunno") + print(car.start()) + print(car.turn("left")) + print(car.speed_up(150)) + print(car.speed_down(50)) + print(car.beep()) + print(car.stop()) + print('\n'*2) + + truck = Car("Green", "Samsung", "Truck", 75.0, "Kinda Sorda box") + print(truck.start()) + print(truck.turn("straight")) + print(truck.speed_up(12)) + print(truck.speed_down(12)) + print(truck.speed_up(1)) + print(truck.beep()) + print(truck.stop()) + + +def task5(): + tl = TrafficLight() + while True: + tl.switching() + print()