From 14fb4540d72a332f1e58ea45c004ee2821cbac93 Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Sat, 24 Sep 2022 15:29:50 +0300 Subject: [PATCH 1/9] Array realization --- homeworks/ALTokarev7/1/array.py | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 homeworks/ALTokarev7/1/array.py diff --git a/homeworks/ALTokarev7/1/array.py b/homeworks/ALTokarev7/1/array.py new file mode 100644 index 0000000..1cc3889 --- /dev/null +++ b/homeworks/ALTokarev7/1/array.py @@ -0,0 +1,39 @@ +class Array(object): + + def __init__(self, *args): + self._data = args + + def __len__(self): + return len(self._data) + + def __str__(self): + return str(self._data) + + def __getitem__(self, ind): + return self._data[ind] + + def __iter__(self): + return iter(self._data) + + def __add__(self, other): + res = Array() + res._data = self._data + other._data + return res + + def append(self, arg): + self._data = self._data + (arg,) + + def index(self, obj): + if obj in self._data: + return( self._data.index(obj) ) + return -1 + +def main(): + array_a = Array() + array_b = array_a + Array(1,2,3) + print(Array(1,2,3,4,5)) + +if __name__ == "__main__": + main() + + From 619cfc859505fa0e90a9a64e02c97fba22dd7413 Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Sat, 24 Sep 2022 15:57:20 +0300 Subject: [PATCH 2/9] Array realization --- homeworks/ALTokarev7/1/array.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/homeworks/ALTokarev7/1/array.py b/homeworks/ALTokarev7/1/array.py index 1cc3889..1465da1 100644 --- a/homeworks/ALTokarev7/1/array.py +++ b/homeworks/ALTokarev7/1/array.py @@ -29,9 +29,21 @@ def index(self, obj): return -1 def main(): - array_a = Array() - array_b = array_a + Array(1,2,3) - print(Array(1,2,3,4,5)) + mas_a = Array(1,2) + print(f'first array = {mas_a}' ) + mas_b = Array(3,4,5,6) + print(f'second array = {mas_b}' ) + mas_a.append(33) + print(f'first array after append(33) = {mas_a}') + mas_sum = mas_a + mas_b + print(f'array of sum first and second: {mas_sum}') + print(f'length of sum array is {len(mas_sum)}') + print(f'index of element 1 in sum array is {mas_sum.index(1)}') + + for el in mas_sum: #array working with for loop + print(el) + + print(f'Sum array el number [1] is {mas_sum[1]}') if __name__ == "__main__": main() From 222d78dd95c8541e12fa08b66be55011e30fb2af Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Wed, 28 Sep 2022 20:35:25 +0300 Subject: [PATCH 3/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- practice/ALTokarev7/1/game.py | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 practice/ALTokarev7/1/game.py diff --git a/practice/ALTokarev7/1/game.py b/practice/ALTokarev7/1/game.py new file mode 100644 index 0000000..cafb4d5 --- /dev/null +++ b/practice/ALTokarev7/1/game.py @@ -0,0 +1,78 @@ +import random + +# Empty tile, there's only one empty cell on a field: +EMPTY_MARK = 'x' + +# Dictionary of possible moves if a form of: +# key -> delta to move the empty tile on a field. +MOVES = { + 'w': -4, + 's': 4, + 'a': -1, + 'd': 1, +} + +CONTROL_BUTTONS = ("w", "s","a","d") + +TRUE_POS = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,"x") + +def shuffle_field(): + + shuffled_tiles = list(TRUE_POS) + + for move in range(100): + perform_move(shuffled_tiles, random.choice(CONTROL_BUTTONS)) + + return shuffled_tiles + + +def print_field(field): + + for i in range(4): + print("|", field[i*4],"\t", + field[i*4 + 1],"\t", + field[i*4 + 2],"\t", + field[i*4 + 3],"\t","|") + + return + + +def is_game_finished(field): + if tuple(field) == TRUE_POS: + return True + return False + + +def perform_move(field, key): + + empty_ind = field.index("x") + + new_ind = empty_ind + MOVES[key] + if new_ind < 0 or new_ind > 15: + return None + + field[empty_ind], field[new_ind] = field[new_ind], field[empty_ind] + return field + +def handle_user_input(): + + move = input("choose you move: ") + while move not in CONTROL_BUTTONS: + print("Enter only : 'w', 's','a','d'") + move = input("choose you move: ") + + return move + +def main(): + + field = shuffle_field() + while not is_game_finished(field): + print_field(field) + if perform_move(field, handle_user_input()) is None: + print("Invalid move!!!") + continue + + print("You`re champion!!!") + +if __name__ == '__main__': + main() From 4e7891176dca362c9de7159f136d806bf8dcec17 Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Wed, 28 Sep 2022 23:08:09 +0300 Subject: [PATCH 4/9] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=20=D0=BA=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- practice/ALTokarev7/1/game.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/practice/ALTokarev7/1/game.py b/practice/ALTokarev7/1/game.py index cafb4d5..23b7c8a 100644 --- a/practice/ALTokarev7/1/game.py +++ b/practice/ALTokarev7/1/game.py @@ -16,11 +16,11 @@ TRUE_POS = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,"x") + def shuffle_field(): shuffled_tiles = list(TRUE_POS) - - for move in range(100): + for move in range(1024): perform_move(shuffled_tiles, random.choice(CONTROL_BUTTONS)) return shuffled_tiles @@ -29,27 +29,32 @@ def shuffle_field(): def print_field(field): for i in range(4): - print("|", field[i*4],"\t", - field[i*4 + 1],"\t", - field[i*4 + 2],"\t", - field[i*4 + 3],"\t","|") - + print(field[i*4],'\t', + field[i*4 + 1],'\t', + field[i*4 + 2],'\t', + field[i*4 + 3], + ) return def is_game_finished(field): + if tuple(field) == TRUE_POS: return True + return False def perform_move(field, key): empty_ind = field.index("x") - new_ind = empty_ind + MOVES[key] - if new_ind < 0 or new_ind > 15: + if new_ind < 0 or new_ind > (len(field) - 1): return None + + if key == 'a' or key =='d': + if (empty_ind // 4) != (new_ind // 4): + return None field[empty_ind], field[new_ind] = field[new_ind], field[empty_ind] return field @@ -64,13 +69,12 @@ def handle_user_input(): return move def main(): - + field = shuffle_field() while not is_game_finished(field): print_field(field) if perform_move(field, handle_user_input()) is None: print("Invalid move!!!") - continue print("You`re champion!!!") From a06f5526875f011d6a561d5798595b05fc1422c8 Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Sun, 2 Oct 2022 17:08:59 +0300 Subject: [PATCH 5/9] homework and practice are ready --- homeworks/ALTokarev7/2/contract.py | 26 ++++++++++++++++++++++++++ practice/ALTokarev7/1/game.py | 23 +++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 homeworks/ALTokarev7/2/contract.py diff --git a/homeworks/ALTokarev7/2/contract.py b/homeworks/ALTokarev7/2/contract.py new file mode 100644 index 0000000..0232661 --- /dev/null +++ b/homeworks/ALTokarev7/2/contract.py @@ -0,0 +1,26 @@ +class ContractError(Exception): + """We use this error when someone breaks our contract.""" + +#: Special value, that indicates that validation for this type is not required. +Any = object() + +def contract(arg_types=None, return_type=None, raises=None): + def decorator(func): + def wrapped(*args): + if arg_types != None: + for num in range(len(args)): + if arg_types[num] != Any and arg_types[num] != None: + if type(args[num]) != arg_types[num]: + raise ContractError + try: + ret = func(*args) + except Exception as ex: + if type(ex) in raises: + raise ex + else: raise ContractError from ex + if return_type != None and return_type != Any: + if type(ret) != return_type: + raise ContractError + return ret + return wrapped + return decorator \ No newline at end of file diff --git a/practice/ALTokarev7/1/game.py b/practice/ALTokarev7/1/game.py index 23b7c8a..f3fffb4 100644 --- a/practice/ALTokarev7/1/game.py +++ b/practice/ALTokarev7/1/game.py @@ -16,37 +16,30 @@ TRUE_POS = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,"x") - def shuffle_field(): - shuffled_tiles = list(TRUE_POS) for move in range(1024): perform_move(shuffled_tiles, random.choice(CONTROL_BUTTONS)) return shuffled_tiles - def print_field(field): - for i in range(4): - print(field[i*4],'\t', - field[i*4 + 1],'\t', - field[i*4 + 2],'\t', - field[i*4 + 3], - ) + print( + field[i*4],'\t', + field[i*4 + 1],'\t', + field[i*4 + 2],'\t', + field[i*4 + 3], + ) return - def is_game_finished(field): - if tuple(field) == TRUE_POS: return True - + return False - def perform_move(field, key): - empty_ind = field.index("x") new_ind = empty_ind + MOVES[key] if new_ind < 0 or new_ind > (len(field) - 1): @@ -60,7 +53,6 @@ def perform_move(field, key): return field def handle_user_input(): - move = input("choose you move: ") while move not in CONTROL_BUTTONS: print("Enter only : 'w', 's','a','d'") @@ -69,7 +61,6 @@ def handle_user_input(): return move def main(): - field = shuffle_field() while not is_game_finished(field): print_field(field) From 752e6c9807be387faa2efeb881861558db516fb4 Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Mon, 10 Oct 2022 18:52:24 +0300 Subject: [PATCH 6/9] homework5 (task manager) already done --- homeworks/ALTokarev7/5/todo/__init__.py | 0 homeworks/ALTokarev7/5/todo/__main__.py | 28 +++++ homeworks/ALTokarev7/5/todo/commands.py | 106 ++++++++++++++++++ .../ALTokarev7/5/todo/custom_exceptions.py | 2 + homeworks/ALTokarev7/5/todo/models.py | 71 ++++++++++++ homeworks/ALTokarev7/5/todo/reflection.py | 34 ++++++ homeworks/ALTokarev7/5/todo/runtime.py | 51 +++++++++ homeworks/ALTokarev7/5/todo/storage.py | 21 ++++ 8 files changed, 313 insertions(+) create mode 100644 homeworks/ALTokarev7/5/todo/__init__.py create mode 100644 homeworks/ALTokarev7/5/todo/__main__.py create mode 100644 homeworks/ALTokarev7/5/todo/commands.py create mode 100644 homeworks/ALTokarev7/5/todo/custom_exceptions.py create mode 100644 homeworks/ALTokarev7/5/todo/models.py create mode 100644 homeworks/ALTokarev7/5/todo/reflection.py create mode 100644 homeworks/ALTokarev7/5/todo/runtime.py create mode 100644 homeworks/ALTokarev7/5/todo/storage.py diff --git a/homeworks/ALTokarev7/5/todo/__init__.py b/homeworks/ALTokarev7/5/todo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/homeworks/ALTokarev7/5/todo/__main__.py b/homeworks/ALTokarev7/5/todo/__main__.py new file mode 100644 index 0000000..55f9f2c --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/__main__.py @@ -0,0 +1,28 @@ +""" +Main file. Contains program execution logic. +""" + +from todo.custom_exceptions import UserExitException +from todo.runtime import parse_user_input, perform_command + + +def main(): + """ + Main method, works infinitely until user runs `exit` command. + Or hits `Ctrl+C` in the console. + """ + while True: + try: + perform_command(parse_user_input()) + except UserExitException: + break + except Exception as ex: + print('You have done something wrong!', ex) + + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print() + print('Shutting down, bye!') diff --git a/homeworks/ALTokarev7/5/todo/commands.py b/homeworks/ALTokarev7/5/todo/commands.py new file mode 100644 index 0000000..9d0f17a --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/commands.py @@ -0,0 +1,106 @@ + +from todo.custom_exceptions import UserExitException +from todo.models import BaseItem +from todo.reflection import find_classes + + +class BaseCommand(object): + label: str + + def perform(self, store): + raise NotImplementedError() + + +class ListCommand(BaseCommand): + label = 'list' + + def perform(self, store): + if len(store.items) == 0: + print('There are no items in the storage.') + return + + for index, obj in enumerate(store.items): + print('{0}: {1}'.format(index, str(obj))) + + +class NewCommand(BaseCommand): + label = 'new' + + def perform(self, store): + classes = self._load_item_classes() + + print('Select item type:') + for index, name in enumerate(classes.keys()): + print('{0}: {1}'.format(index, name)) + + selection = None + selected_key = None + + while True: + try: + selected_key = self._select_item(classes) + except ValueError: + print('Bad input, try again.') + except IndexError: + print('Wrong index, try again.') + else: + break + + selected_class = classes[selected_key] + print('Selected: {0}'.format(selected_class.__name__)) + print() + + new_object = selected_class.construct() + + store.items.append(new_object) + print('Added {0}'.format(str(new_object))) + print() + return new_object + + def _load_item_classes(self) -> dict: + # Dynamic load: + return dict(find_classes(BaseItem)) + + def _select_item(self, classes): + selection = int(input('Input number: ')) + if selection < 0: + raise IndexError('Index needs to be >0') + return list(classes.keys())[selection] + +class DoneCommand(BaseCommand): + label = 'done' + + def perform(self, store): + num = int(input('Input number of item to change item status on done: ')) + if num < 0: + raise IndexError('Index needs to be >0') + if num >= len(store.items): + raise IndexError('Wrong index, try again.') + + store.items[num].done = True + + print('item {0} is done!'.format(store.items[num])) + print() + + +class UndoneCommand(BaseCommand): + label = 'undone' + + def perform(self, store): + num = int(input('Input number of item to change item status on undone: ')) + if num < 0: + raise IndexError('Index needs to be >0') + if num >= len(store.items): + raise IndexError('Wrong index, try again.') + + store.items[num].done = False + + print('item {0} is undone!'.format(store.items[num])) + print() + + +class ExitCommand(BaseCommand): + label = 'exit' + + def perform(self, _store): + raise UserExitException('See you next time!') diff --git a/homeworks/ALTokarev7/5/todo/custom_exceptions.py b/homeworks/ALTokarev7/5/todo/custom_exceptions.py new file mode 100644 index 0000000..5e8963c --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/custom_exceptions.py @@ -0,0 +1,2 @@ +class UserExitException(Exception): + """We use this exception when user wants to exit.""" diff --git a/homeworks/ALTokarev7/5/todo/models.py b/homeworks/ALTokarev7/5/todo/models.py new file mode 100644 index 0000000..205c0d8 --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/models.py @@ -0,0 +1,71 @@ +class BaseItem(object): + + status = {False : '-', True : '+'} + + def __init__(self, heading): + self.heading = heading + self.done = False # TODO: make sure we can use it... + + def __repr__(self): + return self.__class__.__name__ + + def __str__(self): + return '{0} {1}'.format( + self.status[self.done], + self.__class__.__name__[:-4] + ) + + @classmethod + def construct(cls): + raise NotImplementedError() + + +class ToDoItem(BaseItem): + def __str__(self): + return '{0}: {1}'.format( + super().__str__(), + self.heading, + ) + + @classmethod + def construct(cls): + heading = input('Input heading: ') + return cls(heading) + + +class ToBuyItem(BaseItem): + def __init__(self, heading, price): + super().__init__(heading) + self.price = price + + def __str__(self): + return '{0}: {1} for {2}'.format( + super().__str__(), + self.heading, + self.price, + ) + + @classmethod + def construct(cls): + heading = input('Input heading: ') + price = input('Input price: ') + return cls(heading, price) + + +class ToReadItem(BaseItem): + def __init__(self, heading, url): + super().__init__(heading) + self.url = url + + def __str__(self): + return '{0}: {1} from {2}'.format( + super().__str__(), + self.heading, + self.url, + ) + + @classmethod + def construct(cls): + heading = input('Input heading: ') + url = input('Input url: ') + return cls(heading, url) diff --git a/homeworks/ALTokarev7/5/todo/reflection.py b/homeworks/ALTokarev7/5/todo/reflection.py new file mode 100644 index 0000000..dee9f85 --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/reflection.py @@ -0,0 +1,34 @@ +import inspect +import sys + + +def find_classes(base_class) -> tuple: + """ + Finds all subclasses of a class inside module. + + :param base_class: Base class to search children. + :return: tuple of subclasses + """ + return inspect.getmembers( + sys.modules[base_class.__module__], + _reflect_filter(base_class), + ) + + +def _reflect_filter(base_class): + """ + Reflection is used to load modules dynamically. + + This method is complex. It does some dark magic. + How is it even possible to understand it? + + :param base_class: Target base class + :return: function to filter only subclasses of `base_class` + """ + def class_filter(klass): + return inspect.isclass( + klass, + ) and klass.__module__ == base_class.__module__ and issubclass( + klass, base_class, + ) and klass is not base_class + return class_filter diff --git a/homeworks/ALTokarev7/5/todo/runtime.py b/homeworks/ALTokarev7/5/todo/runtime.py new file mode 100644 index 0000000..a21fa30 --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/runtime.py @@ -0,0 +1,51 @@ +from todo.commands import BaseCommand +from todo.custom_exceptions import UserExitException +from todo.reflection import find_classes +from todo.storage import Storage + + +def get_routes() -> dict: + """ + This function contains the dictionary of possible commands. + :return: `dict` of possible commands, with the format: `name -> class` + """ + routes = find_classes(BaseCommand) + return { + route().label: route + for _, route in routes + } + + +def perform_command(command: str) -> None: + """ + Performs the command by name. + Stores the result in `Storage()`. + :param command: command name, selected by user. + """ + command = command.lower() + routes = get_routes() + + try: + command_class = routes[command] + except KeyError: + print('Bad command, try again.') + return + + command_inst = command_class() + storage = Storage() + + try: + command_inst.perform(storage) + except UserExitException as ex: + # Handling `exit` command. + print(ex) + raise + + +def parse_user_input(): + """ + Вернёт одну из команд exit list new + """ + commands = get_routes().keys() + message = 'Input your command: ({0}): '.format('|'.join(commands)) + return input(message) diff --git a/homeworks/ALTokarev7/5/todo/storage.py b/homeworks/ALTokarev7/5/todo/storage.py new file mode 100644 index 0000000..ef58690 --- /dev/null +++ b/homeworks/ALTokarev7/5/todo/storage.py @@ -0,0 +1,21 @@ +class Storage(object): # storage = Storge() + """ + Singleton storage. + + Read more about singleton design pattern: + https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python + https://en.wikipedia.org/wiki/Singleton_pattern + + It is used to emulate in-memory storage. + It should be replaced with a database in a real application. + """ + + obj = None + items = None + + @classmethod + def __new__(cls, *args): + if cls.obj is None: + cls.obj = object.__new__(cls) + cls.items = [] + return cls.obj From 329308f6a7e4cc3b551d58856d1e3f6cba9fae2e Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Tue, 18 Oct 2022 22:40:10 +0300 Subject: [PATCH 7/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ALTokarev7/6/my-awesome-script/README.md | 0 .../my_awesome_script/__init__.py | 0 .../my_awesome_script/__main__.py | 8 + .../my_awesome_script/commands.py | 16 ++ .../my_awesome_script/parse_input.py | 19 +++ .../6/my-awesome-script/poetry.lock | 145 ++++++++++++++++++ .../6/my-awesome-script/pyproject.toml | 26 ++++ .../6/my-awesome-script/tests/__init__.py | 0 8 files changed, 214 insertions(+) create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/README.md create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__init__.py create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/poetry.lock create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/pyproject.toml create mode 100644 homeworks/ALTokarev7/6/my-awesome-script/tests/__init__.py diff --git a/homeworks/ALTokarev7/6/my-awesome-script/README.md b/homeworks/ALTokarev7/6/my-awesome-script/README.md new file mode 100644 index 0000000..e69de29 diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__init__.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py new file mode 100644 index 0000000..4f6657f --- /dev/null +++ b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py @@ -0,0 +1,8 @@ +from .parse_input import parse_input +def main(): + parse_input() + + +if __name__ == '__main__': + main() + \ No newline at end of file diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py new file mode 100644 index 0000000..f520ae4 --- /dev/null +++ b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py @@ -0,0 +1,16 @@ +from pygments import highlight +from pygments.formatters import TerminalFormatter +from pygments.lexers import PythonLexer +from cowpy import cow +from datetime import datetime +import pytz + +def highligh(text: str): + print(highlight(text,PythonLexer(),TerminalFormatter())) + +def cowsay(text: str): + print(cow.milk_random_cow(text)) + +def time(timezone): + local_date = datetime.now(pytz.timezone(timezone)) + print("{0} {1}".format(local_date.date(), local_date.time())) diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py new file mode 100644 index 0000000..39143de --- /dev/null +++ b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py @@ -0,0 +1,19 @@ +import argparse +from .commands import * + +comands_dict = {'highligh' : highligh, 'cowsay' : cowsay, 'time': time} + +def parse_input(): + parser = argparse.ArgumentParser() + parser.add_argument('operation',type = str, + choices=['highligh', 'cowsay', 'time'], + help = 'Enter comand from this list' + ) + parser.add_argument('param', type = str, + help = 'Enter for highligh or cowsay,or for time' + ) + args = parser.parse_args() + use_comand(args.operation, args.param) + +def use_comand(comand, param): + comands_dict[comand](param) diff --git a/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock b/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock new file mode 100644 index 0000000..aea47d7 --- /dev/null +++ b/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock @@ -0,0 +1,145 @@ +[[package]] +name = "argparse" +version = "1.4.0" +description = "Python command-line parsing library" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "cowpy" +version = "1.1.5" +description = "" +category = "main" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "datetime" +version = "4.7" +description = "This package provides a DateTime data type, as known from Zope. Unless you need to communicate with Zope APIs, you're probably better off using Python's built-in datetime module." +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +pytz = "*" +"zope.interface" = "*" + +[[package]] +name = "pygments" +version = "2.13.0" +description = "Pygments is a syntax highlighting package written in Python." +category = "main" +optional = false +python-versions = ">=3.6" + +[package.extras] +plugins = ["importlib-metadata"] + +[[package]] +name = "pytz" +version = "2022.5" +description = "World timezone definitions, modern and historical" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "setuptools" +version = "65.5.0" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mock", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + +[[package]] +name = "zope-interface" +version = "5.5.0" +description = "Interfaces for Python" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.dependencies] +setuptools = "*" + +[package.extras] +docs = ["Sphinx", "repoze.sphinx.autointerface"] +test = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] +testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] + +[metadata] +lock-version = "1.1" +python-versions = "^3.10" +content-hash = "427dbe263852ea34d11cd2796c9b62eb5242b8a53b78447786db16318c8aa861" + +[metadata.files] +argparse = [ + {file = "argparse-1.4.0-py2.py3-none-any.whl", hash = "sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314"}, + {file = "argparse-1.4.0.tar.gz", hash = "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4"}, +] +cowpy = [ + {file = "cowpy-1.1.5-py3-none-any.whl", hash = "sha256:de5ae7646dd30b4936013666c6bd019af9cf411cc3b377c8538cfd8414262921"}, + {file = "cowpy-1.1.5.tar.gz", hash = "sha256:089172db1d88c30a2e1b741b18945ee84170bd943a3ca71948e4ae3a3255e554"}, +] +datetime = [ + {file = "DateTime-4.7-py2.py3-none-any.whl", hash = "sha256:b8d2d605cfb5fed0da86f9ad64d0973c6f84b21939d49265e135811b33ee8113"}, + {file = "DateTime-4.7.tar.gz", hash = "sha256:7ff7c4a857f08b73db17a85fc54f102d065ad16e7db0133e699c5f1b37e41478"}, +] +pygments = [ + {file = "Pygments-2.13.0-py3-none-any.whl", hash = "sha256:f643f331ab57ba3c9d89212ee4a2dabc6e94f117cf4eefde99a0574720d14c42"}, + {file = "Pygments-2.13.0.tar.gz", hash = "sha256:56a8508ae95f98e2b9bdf93a6be5ae3f7d8af858b43e02c5a2ff083726be40c1"}, +] +pytz = [ + {file = "pytz-2022.5-py2.py3-none-any.whl", hash = "sha256:335ab46900b1465e714b4fda4963d87363264eb662aab5e65da039c25f1f5b22"}, + {file = "pytz-2022.5.tar.gz", hash = "sha256:c4d88f472f54d615e9cd582a5004d1e5f624854a6a27a6211591c251f22a6914"}, +] +setuptools = [ + {file = "setuptools-65.5.0-py3-none-any.whl", hash = "sha256:f62ea9da9ed6289bfe868cd6845968a2c854d1427f8548d52cae02a42b4f0356"}, + {file = "setuptools-65.5.0.tar.gz", hash = "sha256:512e5536220e38146176efb833d4a62aa726b7bbff82cfbc8ba9eaa3996e0b17"}, +] +zope-interface = [ + {file = "zope.interface-5.5.0-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:2cb3003941f5f4fa577479ac6d5db2b940acb600096dd9ea9bf07007f5cab46f"}, + {file = "zope.interface-5.5.0-cp27-cp27m-win32.whl", hash = "sha256:8c791f4c203ccdbcda588ea4c8a6e4353e10435ea48ddd3d8734a26fe9714cba"}, + {file = "zope.interface-5.5.0-cp27-cp27m-win_amd64.whl", hash = "sha256:3eedf3d04179774d750e8bb4463e6da350956a50ed44d7b86098e452d7ec385e"}, + {file = "zope.interface-5.5.0-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:58a66c2020a347973168a4a9d64317bac52f9fdfd3e6b80b252be30da881a64e"}, + {file = "zope.interface-5.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da7912ae76e1df6a1fb841b619110b1be4c86dfb36699d7fd2f177105cdea885"}, + {file = "zope.interface-5.5.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:423c074e404f13e6fa07f4454f47fdbb38d358be22945bc812b94289d9142374"}, + {file = "zope.interface-5.5.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:7bdcec93f152e0e1942102537eed7b166d6661ae57835b20a52a2a3d6a3e1bf3"}, + {file = "zope.interface-5.5.0-cp310-cp310-win32.whl", hash = "sha256:03f5ae315db0d0de668125d983e2a819a554f3fdb2d53b7e934e3eb3c3c7375d"}, + {file = "zope.interface-5.5.0-cp310-cp310-win_amd64.whl", hash = "sha256:8b9f153208d74ccfa25449a0c6cb756ab792ce0dc99d9d771d935f039b38740c"}, + {file = "zope.interface-5.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:aeac590cce44e68ee8ad0b8ecf4d7bf15801f102d564ca1b0eb1f12f584ee656"}, + {file = "zope.interface-5.5.0-cp35-cp35m-win32.whl", hash = "sha256:7d9ec1e6694af39b687045712a8ad14ddcb568670d5eb1b66b48b98b9312afba"}, + {file = "zope.interface-5.5.0-cp35-cp35m-win_amd64.whl", hash = "sha256:d18fb0f6c8169d26044128a2e7d3c39377a8a151c564e87b875d379dbafd3930"}, + {file = "zope.interface-5.5.0-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:0eb2b3e84f48dd9cfc8621c80fba905d7e228615c67f76c7df7c716065669bb6"}, + {file = "zope.interface-5.5.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:df6593e150d13cfcce69b0aec5df7bc248cb91e4258a7374c129bb6d56b4e5ca"}, + {file = "zope.interface-5.5.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:9dc4493aa3d87591e3d2bf1453e25b98038c839ca8e499df3d7106631b66fe83"}, + {file = "zope.interface-5.5.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:5c6023ae7defd052cf76986ce77922177b0c2f3913bea31b5b28fbdf6cb7099e"}, + {file = "zope.interface-5.5.0-cp36-cp36m-win32.whl", hash = "sha256:a69c28d85bb7cf557751a5214cb3f657b2b035c8c96d71080c1253b75b79b69b"}, + {file = "zope.interface-5.5.0-cp36-cp36m-win_amd64.whl", hash = "sha256:85dd6dd9aaae7a176948d8bb62e20e2968588fd787c29c5d0d964ab475168d3d"}, + {file = "zope.interface-5.5.0-cp37-cp37m-macosx_10_15_x86_64.whl", hash = "sha256:970661ece2029915b8f7f70892e88404340fbdefd64728380cad41c8dce14ff4"}, + {file = "zope.interface-5.5.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1e3495bb0cdcea212154e558082c256f11b18031f05193ae2fb85d048848db14"}, + {file = "zope.interface-5.5.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:3f68404edb1a4fb6aa8a94675521ca26c83ebbdbb90e894f749ae0dc4ca98418"}, + {file = "zope.interface-5.5.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:740f3c1b44380658777669bcc42f650f5348e53797f2cee0d93dc9b0f9d7cc69"}, + {file = "zope.interface-5.5.0-cp37-cp37m-win32.whl", hash = "sha256:006f8dd81fae28027fc28ada214855166712bf4f0bfbc5a8788f9b70982b9437"}, + {file = "zope.interface-5.5.0-cp37-cp37m-win_amd64.whl", hash = "sha256:43490ad65d4c64e45a30e51a2beb7a6b63e1ff395302ad22392224eb618476d6"}, + {file = "zope.interface-5.5.0-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:f70726b60009433111fe9928f5d89cbb18962411d33c45fb19eb81b9bbd26fcd"}, + {file = "zope.interface-5.5.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cfa614d049667bed1c737435c609c0956c5dc0dbafdc1145ee7935e4658582cb"}, + {file = "zope.interface-5.5.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:58a975f89e4584d0223ab813c5ba4787064c68feef4b30d600f5e01de90ae9ce"}, + {file = "zope.interface-5.5.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:37ec9ade9902f412cc7e7a32d71f79dec3035bad9bd0170226252eed88763c48"}, + {file = "zope.interface-5.5.0-cp38-cp38-win32.whl", hash = "sha256:be11fce0e6af6c0e8d93c10ef17b25aa7c4acb7ec644bff2596c0d639c49e20f"}, + {file = "zope.interface-5.5.0-cp38-cp38-win_amd64.whl", hash = "sha256:cbbf83914b9a883ab324f728de869f4e406e0cbcd92df7e0a88decf6f9ab7d5a"}, + {file = "zope.interface-5.5.0-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:26c1456520fdcafecc5765bec4783eeafd2e893eabc636908f50ee31fe5c738c"}, + {file = "zope.interface-5.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:47ff078734a1030c48103422a99e71a7662d20258c00306546441adf689416f7"}, + {file = "zope.interface-5.5.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:687cab7f9ae18d2c146f315d0ca81e5ffe89a139b88277afa70d52f632515854"}, + {file = "zope.interface-5.5.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:d80f6236b57a95eb19d5e47eb68d0296119e1eff6deaa2971ab8abe3af918420"}, + {file = "zope.interface-5.5.0-cp39-cp39-win32.whl", hash = "sha256:9cdc4e898d3b1547d018829fd4a9f403e52e51bba24be0fbfa37f3174e1ef797"}, + {file = "zope.interface-5.5.0-cp39-cp39-win_amd64.whl", hash = "sha256:6566b3d2657e7609cd8751bcb1eab1202b1692a7af223035a5887d64bb3a2f3b"}, + {file = "zope.interface-5.5.0.tar.gz", hash = "sha256:700ebf9662cf8df70e2f0cb4988e078c53f65ee3eefd5c9d80cf988c4175c8e3"}, +] diff --git a/homeworks/ALTokarev7/6/my-awesome-script/pyproject.toml b/homeworks/ALTokarev7/6/my-awesome-script/pyproject.toml new file mode 100644 index 0000000..7c0466b --- /dev/null +++ b/homeworks/ALTokarev7/6/my-awesome-script/pyproject.toml @@ -0,0 +1,26 @@ +[tool.poetry] +name = "my-awesome-script" +version = "0.1.0" +description = "It`s my awesome scripts for homework" +authors = ["ALTokarev7 "] +readme = "README.md" +packages = [{include = "my_awesome_script"}] + +[tool.poetry.dependencies] +python = "^3.10" +cowpy = "^1.1.5" +pygments = "^2.13.0" +pytz = "^2022.5" +argparse = "^1.4.0" +datetime = "^4.7" + +[tool.poetry.group.dev.dependencies] +safety = "^2.3.1" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +my-awesome-script = "my_awesome_script.__main__:main" + diff --git a/homeworks/ALTokarev7/6/my-awesome-script/tests/__init__.py b/homeworks/ALTokarev7/6/my-awesome-script/tests/__init__.py new file mode 100644 index 0000000..e69de29 From fa7b81c28a2232e4dcfefc9b3897baaea138e0dc Mon Sep 17 00:00:00 2001 From: ALTokarev7 <94852747+ALTokarev7@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:04:11 +0300 Subject: [PATCH 8/9] Delete README.md --- homeworks/ALTokarev7/6/my-awesome-script/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 homeworks/ALTokarev7/6/my-awesome-script/README.md diff --git a/homeworks/ALTokarev7/6/my-awesome-script/README.md b/homeworks/ALTokarev7/6/my-awesome-script/README.md deleted file mode 100644 index e69de29..0000000 From 7b2071d9c50ced70196fbf67fda81aaee7bffeda Mon Sep 17 00:00:00 2001 From: ALTokarev7 Date: Wed, 19 Oct 2022 00:14:22 +0300 Subject: [PATCH 9/9] flake8 check --- homeworks/ALTokarev7/1/array.py | 32 +- homeworks/ALTokarev7/2/contract.py | 21 +- homeworks/ALTokarev7/5/todo/commands.py | 10 +- homeworks/ALTokarev7/5/todo/models.py | 6 +- homeworks/ALTokarev7/5/todo/runtime.py | 2 +- .../my_awesome_script/__main__.py | 3 +- .../my_awesome_script/commands.py | 5 +- .../my_awesome_script/parse_input.py | 17 +- .../6/my-awesome-script/poetry.lock | 305 +++++++++++++++++- practice/ALTokarev7/1/game.py | 31 +- 10 files changed, 377 insertions(+), 55 deletions(-) diff --git a/homeworks/ALTokarev7/1/array.py b/homeworks/ALTokarev7/1/array.py index 1465da1..19b2923 100644 --- a/homeworks/ALTokarev7/1/array.py +++ b/homeworks/ALTokarev7/1/array.py @@ -1,8 +1,8 @@ class Array(object): def __init__(self, *args): - self._data = args - + self._data = args + def __len__(self): return len(self._data) @@ -11,41 +11,41 @@ def __str__(self): def __getitem__(self, ind): return self._data[ind] - + def __iter__(self): - return iter(self._data) - + return iter(self._data) + def __add__(self, other): res = Array() res._data = self._data + other._data - return res + return res def append(self, arg): self._data = self._data + (arg,) def index(self, obj): if obj in self._data: - return( self._data.index(obj) ) + return (self._data.index(obj)) return -1 + def main(): - mas_a = Array(1,2) - print(f'first array = {mas_a}' ) - mas_b = Array(3,4,5,6) - print(f'second array = {mas_b}' ) - mas_a.append(33) + mas_a = Array(1, 2) + print(f'first array = {mas_a}') + mas_b = Array(3, 4, 5, 6) + print(f'second array = {mas_b}') + mas_a.append(33) print(f'first array after append(33) = {mas_a}') - mas_sum = mas_a + mas_b + mas_sum = mas_a + mas_b print(f'array of sum first and second: {mas_sum}') print(f'length of sum array is {len(mas_sum)}') print(f'index of element 1 in sum array is {mas_sum.index(1)}') - for el in mas_sum: #array working with for loop + for el in mas_sum: print(el) print(f'Sum array el number [1] is {mas_sum[1]}') + if __name__ == "__main__": main() - - diff --git a/homeworks/ALTokarev7/2/contract.py b/homeworks/ALTokarev7/2/contract.py index 0232661..e320e70 100644 --- a/homeworks/ALTokarev7/2/contract.py +++ b/homeworks/ALTokarev7/2/contract.py @@ -1,26 +1,29 @@ class ContractError(Exception): """We use this error when someone breaks our contract.""" + #: Special value, that indicates that validation for this type is not required. Any = object() + def contract(arg_types=None, return_type=None, raises=None): def decorator(func): def wrapped(*args): - if arg_types != None: + if arg_types is not None: for num in range(len(args)): - if arg_types[num] != Any and arg_types[num] != None: - if type(args[num]) != arg_types[num]: - raise ContractError + if arg_types[num] != Any and arg_types[num] is not None: + if type(args[num]) != arg_types[num]: + raise ContractError try: ret = func(*args) except Exception as ex: if type(ex) in raises: raise ex - else: raise ContractError from ex - if return_type != None and return_type != Any: + else: + raise ContractError from ex + if return_type is not None and return_type != Any: if type(ret) != return_type: - raise ContractError - return ret + raise ContractError + return ret return wrapped - return decorator \ No newline at end of file + return decorator diff --git a/homeworks/ALTokarev7/5/todo/commands.py b/homeworks/ALTokarev7/5/todo/commands.py index 9d0f17a..505ac9d 100644 --- a/homeworks/ALTokarev7/5/todo/commands.py +++ b/homeworks/ALTokarev7/5/todo/commands.py @@ -33,7 +33,6 @@ def perform(self, store): for index, name in enumerate(classes.keys()): print('{0}: {1}'.format(index, name)) - selection = None selected_key = None while True: @@ -67,18 +66,19 @@ def _select_item(self, classes): raise IndexError('Index needs to be >0') return list(classes.keys())[selection] + class DoneCommand(BaseCommand): label = 'done' def perform(self, store): - num = int(input('Input number of item to change item status on done: ')) + num = int(input('Input number of item to change status on done: ')) if num < 0: raise IndexError('Index needs to be >0') if num >= len(store.items): raise IndexError('Wrong index, try again.') store.items[num].done = True - + print('item {0} is done!'.format(store.items[num])) print() @@ -87,14 +87,14 @@ class UndoneCommand(BaseCommand): label = 'undone' def perform(self, store): - num = int(input('Input number of item to change item status on undone: ')) + num = int(input('Input number of item to change status on undone: ')) if num < 0: raise IndexError('Index needs to be >0') if num >= len(store.items): raise IndexError('Wrong index, try again.') store.items[num].done = False - + print('item {0} is undone!'.format(store.items[num])) print() diff --git a/homeworks/ALTokarev7/5/todo/models.py b/homeworks/ALTokarev7/5/todo/models.py index 205c0d8..24e2347 100644 --- a/homeworks/ALTokarev7/5/todo/models.py +++ b/homeworks/ALTokarev7/5/todo/models.py @@ -1,11 +1,11 @@ class BaseItem(object): - status = {False : '-', True : '+'} + status = {False: '-', True: '+'} def __init__(self, heading): self.heading = heading self.done = False # TODO: make sure we can use it... - + def __repr__(self): return self.__class__.__name__ @@ -14,7 +14,7 @@ def __str__(self): self.status[self.done], self.__class__.__name__[:-4] ) - + @classmethod def construct(cls): raise NotImplementedError() diff --git a/homeworks/ALTokarev7/5/todo/runtime.py b/homeworks/ALTokarev7/5/todo/runtime.py index a21fa30..e63fa50 100644 --- a/homeworks/ALTokarev7/5/todo/runtime.py +++ b/homeworks/ALTokarev7/5/todo/runtime.py @@ -23,7 +23,7 @@ def perform_command(command: str) -> None: :param command: command name, selected by user. """ command = command.lower() - routes = get_routes() + routes = get_routes() try: command_class = routes[command] diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py index 4f6657f..b6b865c 100644 --- a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py +++ b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/__main__.py @@ -1,8 +1,9 @@ from .parse_input import parse_input + + def main(): parse_input() if __name__ == '__main__': main() - \ No newline at end of file diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py index f520ae4..133d3a9 100644 --- a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py +++ b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/commands.py @@ -5,12 +5,15 @@ from datetime import datetime import pytz + def highligh(text: str): - print(highlight(text,PythonLexer(),TerminalFormatter())) + print(highlight(text, PythonLexer(), TerminalFormatter())) + def cowsay(text: str): print(cow.milk_random_cow(text)) + def time(timezone): local_date = datetime.now(pytz.timezone(timezone)) print("{0} {1}".format(local_date.date(), local_date.time())) diff --git a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py index 39143de..44f1518 100644 --- a/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py +++ b/homeworks/ALTokarev7/6/my-awesome-script/my_awesome_script/parse_input.py @@ -1,19 +1,22 @@ -import argparse -from .commands import * +import argparse +from .commands import highligh, cowsay, time + +comands_dict = {'highligh': highligh, 'cowsay': cowsay, 'time': time} -comands_dict = {'highligh' : highligh, 'cowsay' : cowsay, 'time': time} def parse_input(): parser = argparse.ArgumentParser() - parser.add_argument('operation',type = str, + parser.add_argument('operation', type=str, choices=['highligh', 'cowsay', 'time'], - help = 'Enter comand from this list' + help='Enter comand from this list' ) - parser.add_argument('param', type = str, - help = 'Enter for highligh or cowsay,or for time' + parser.add_argument('param', type=str, + help='''Enter for highligh or cowsay, + or for time''' ) args = parser.parse_args() use_comand(args.operation, args.param) + def use_comand(comand, param): comands_dict[comand](param) diff --git a/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock b/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock index aea47d7..b278634 100644 --- a/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock +++ b/homeworks/ALTokarev7/6/my-awesome-script/poetry.lock @@ -6,6 +6,44 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "certifi" +version = "2022.9.24" +description = "Python package for providing Mozilla's CA Bundle." +category = "dev" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "charset-normalizer" +version = "2.1.1" +description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +category = "dev" +optional = false +python-versions = ">=3.6.0" + +[package.extras] +unicode-backport = ["unicodedata2"] + +[[package]] +name = "click" +version = "8.1.3" +description = "Composable command line interface toolkit" +category = "dev" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.5" +description = "Cross-platform colored terminal text." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + [[package]] name = "cowpy" version = "1.1.5" @@ -26,6 +64,78 @@ python-versions = "*" pytz = "*" "zope.interface" = "*" +[[package]] +name = "dparse" +version = "0.6.2" +description = "A parser for Python dependency files" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +packaging = "*" +toml = "*" + +[package.extras] +conda = ["pyyaml"] +pipenv = ["pipenv"] + +[[package]] +name = "flake8" +version = "5.0.4" +description = "the modular source code checker: pep8 pyflakes and co" +category = "main" +optional = false +python-versions = ">=3.6.1" + +[package.dependencies] +mccabe = ">=0.7.0,<0.8.0" +pycodestyle = ">=2.9.0,<2.10.0" +pyflakes = ">=2.5.0,<2.6.0" + +[[package]] +name = "idna" +version = "3.4" +description = "Internationalized Domain Names in Applications (IDNA)" +category = "dev" +optional = false +python-versions = ">=3.5" + +[[package]] +name = "mccabe" +version = "0.7.0" +description = "McCabe checker, plugin for flake8" +category = "main" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "packaging" +version = "21.3" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" + +[[package]] +name = "pycodestyle" +version = "2.9.1" +description = "Python style guide checker" +category = "main" +optional = false +python-versions = ">=3.6" + +[[package]] +name = "pyflakes" +version = "2.5.0" +description = "passive checker of Python programs" +category = "main" +optional = false +python-versions = ">=3.6" + [[package]] name = "pygments" version = "2.13.0" @@ -37,6 +147,17 @@ python-versions = ">=3.6" [package.extras] plugins = ["importlib-metadata"] +[[package]] +name = "pyparsing" +version = "3.0.9" +description = "pyparsing module - Classes and methods to define and execute parsing grammars" +category = "dev" +optional = false +python-versions = ">=3.6.8" + +[package.extras] +diagrams = ["jinja2", "railroad-diagrams"] + [[package]] name = "pytz" version = "2022.5" @@ -45,6 +166,67 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "requests" +version = "2.28.1" +description = "Python HTTP for Humans." +category = "dev" +optional = false +python-versions = ">=3.7, <4" + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = ">=2,<3" +idna = ">=2.5,<4" +urllib3 = ">=1.21.1,<1.27" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] + +[[package]] +name = "ruamel-yaml" +version = "0.17.21" +description = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order" +category = "dev" +optional = false +python-versions = ">=3" + +[package.dependencies] +"ruamel.yaml.clib" = {version = ">=0.2.6", markers = "platform_python_implementation == \"CPython\" and python_version < \"3.11\""} + +[package.extras] +docs = ["ryd"] +jinja2 = ["ruamel.yaml.jinja2 (>=0.2)"] + +[[package]] +name = "ruamel-yaml-clib" +version = "0.2.6" +description = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml" +category = "dev" +optional = false +python-versions = ">=3.5" + +[[package]] +name = "safety" +version = "2.3.1" +description = "Checks installed dependencies for known vulnerabilities and licenses." +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +Click = ">=8.0.2" +dparse = ">=0.6.2" +packaging = ">=21.0" +requests = "*" +"ruamel.yaml" = ">=0.17.21" +setuptools = ">=19.3" + +[package.extras] +github = ["jinja2 (>=3.1.0)", "pygithub (>=1.43.3)"] +gitlab = ["python-gitlab (>=1.3.0)"] + [[package]] name = "setuptools" version = "65.5.0" @@ -58,6 +240,27 @@ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-g testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mock", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" + +[[package]] +name = "urllib3" +version = "1.26.12" +description = "HTTP library with thread-safe connection pooling, file post, and more." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4" + +[package.extras] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] +secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] +socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] + [[package]] name = "zope-interface" version = "5.5.0" @@ -77,13 +280,29 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "427dbe263852ea34d11cd2796c9b62eb5242b8a53b78447786db16318c8aa861" +content-hash = "774e564c03578be71bae30c1822d9e69eab86feb98641c822f680a85e2dfc4e7" [metadata.files] argparse = [ {file = "argparse-1.4.0-py2.py3-none-any.whl", hash = "sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314"}, {file = "argparse-1.4.0.tar.gz", hash = "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4"}, ] +certifi = [ + {file = "certifi-2022.9.24-py3-none-any.whl", hash = "sha256:90c1a32f1d68f940488354e36370f6cca89f0f106db09518524c88d6ed83f382"}, + {file = "certifi-2022.9.24.tar.gz", hash = "sha256:0d9c601124e5a6ba9712dbc60d9c53c21e34f5f641fe83002317394311bdce14"}, +] +charset-normalizer = [ + {file = "charset-normalizer-2.1.1.tar.gz", hash = "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845"}, + {file = "charset_normalizer-2.1.1-py3-none-any.whl", hash = "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"}, +] +click = [ + {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, + {file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, +] +colorama = [ + {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, + {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, +] cowpy = [ {file = "cowpy-1.1.5-py3-none-any.whl", hash = "sha256:de5ae7646dd30b4936013666c6bd019af9cf411cc3b377c8538cfd8414262921"}, {file = "cowpy-1.1.5.tar.gz", hash = "sha256:089172db1d88c30a2e1b741b18945ee84170bd943a3ca71948e4ae3a3255e554"}, @@ -92,18 +311,102 @@ datetime = [ {file = "DateTime-4.7-py2.py3-none-any.whl", hash = "sha256:b8d2d605cfb5fed0da86f9ad64d0973c6f84b21939d49265e135811b33ee8113"}, {file = "DateTime-4.7.tar.gz", hash = "sha256:7ff7c4a857f08b73db17a85fc54f102d065ad16e7db0133e699c5f1b37e41478"}, ] +dparse = [ + {file = "dparse-0.6.2-py3-none-any.whl", hash = "sha256:8097076f1dd26c377f30d4745e6ec18fef42f3bf493933b842ac5bafad8c345f"}, + {file = "dparse-0.6.2.tar.gz", hash = "sha256:d45255bda21f998bc7ddf2afd5e62505ba6134756ba2d42a84c56b0826614dfe"}, +] +flake8 = [ + {file = "flake8-5.0.4-py2.py3-none-any.whl", hash = "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248"}, + {file = "flake8-5.0.4.tar.gz", hash = "sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db"}, +] +idna = [ + {file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"}, + {file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"}, +] +mccabe = [ + {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, +] +packaging = [ + {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, + {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, +] +pycodestyle = [ + {file = "pycodestyle-2.9.1-py2.py3-none-any.whl", hash = "sha256:d1735fc58b418fd7c5f658d28d943854f8a849b01a5d0a1e6f3f3fdd0166804b"}, + {file = "pycodestyle-2.9.1.tar.gz", hash = "sha256:2c9607871d58c76354b697b42f5d57e1ada7d261c261efac224b664affdc5785"}, +] +pyflakes = [ + {file = "pyflakes-2.5.0-py2.py3-none-any.whl", hash = "sha256:4579f67d887f804e67edb544428f264b7b24f435b263c4614f384135cea553d2"}, + {file = "pyflakes-2.5.0.tar.gz", hash = "sha256:491feb020dca48ccc562a8c0cbe8df07ee13078df59813b83959cbdada312ea3"}, +] pygments = [ {file = "Pygments-2.13.0-py3-none-any.whl", hash = "sha256:f643f331ab57ba3c9d89212ee4a2dabc6e94f117cf4eefde99a0574720d14c42"}, {file = "Pygments-2.13.0.tar.gz", hash = "sha256:56a8508ae95f98e2b9bdf93a6be5ae3f7d8af858b43e02c5a2ff083726be40c1"}, ] +pyparsing = [ + {file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"}, + {file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"}, +] pytz = [ {file = "pytz-2022.5-py2.py3-none-any.whl", hash = "sha256:335ab46900b1465e714b4fda4963d87363264eb662aab5e65da039c25f1f5b22"}, {file = "pytz-2022.5.tar.gz", hash = "sha256:c4d88f472f54d615e9cd582a5004d1e5f624854a6a27a6211591c251f22a6914"}, ] +requests = [ + {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, + {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, +] +ruamel-yaml = [ + {file = "ruamel.yaml-0.17.21-py3-none-any.whl", hash = "sha256:742b35d3d665023981bd6d16b3d24248ce5df75fdb4e2924e93a05c1f8b61ca7"}, + {file = "ruamel.yaml-0.17.21.tar.gz", hash = "sha256:8b7ce697a2f212752a35c1ac414471dc16c424c9573be4926b56ff3f5d23b7af"}, +] +ruamel-yaml-clib = [ + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:6e7be2c5bcb297f5b82fee9c665eb2eb7001d1050deaba8471842979293a80b0"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:066f886bc90cc2ce44df8b5f7acfc6a7e2b2e672713f027136464492b0c34d7c"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:221eca6f35076c6ae472a531afa1c223b9c29377e62936f61bc8e6e8bdc5f9e7"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-win32.whl", hash = "sha256:1070ba9dd7f9370d0513d649420c3b362ac2d687fe78c6e888f5b12bf8bc7bee"}, + {file = "ruamel.yaml.clib-0.2.6-cp310-cp310-win_amd64.whl", hash = "sha256:77df077d32921ad46f34816a9a16e6356d8100374579bc35e15bab5d4e9377de"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-macosx_10_6_intel.whl", hash = "sha256:cfdb9389d888c5b74af297e51ce357b800dd844898af9d4a547ffc143fa56751"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:7b2927e92feb51d830f531de4ccb11b320255ee95e791022555971c466af4527"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-win32.whl", hash = "sha256:ada3f400d9923a190ea8b59c8f60680c4ef8a4b0dfae134d2f2ff68429adfab5"}, + {file = "ruamel.yaml.clib-0.2.6-cp35-cp35m-win_amd64.whl", hash = "sha256:de9c6b8a1ba52919ae919f3ae96abb72b994dd0350226e28f3686cb4f142165c"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d67f273097c368265a7b81e152e07fb90ed395df6e552b9fa858c6d2c9f42502"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:72a2b8b2ff0a627496aad76f37a652bcef400fd861721744201ef1b45199ab78"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:d3c620a54748a3d4cf0bcfe623e388407c8e85a4b06b8188e126302bcab93ea8"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-win32.whl", hash = "sha256:9efef4aab5353387b07f6b22ace0867032b900d8e91674b5d8ea9150db5cae94"}, + {file = "ruamel.yaml.clib-0.2.6-cp36-cp36m-win_amd64.whl", hash = "sha256:846fc8336443106fe23f9b6d6b8c14a53d38cef9a375149d61f99d78782ea468"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0847201b767447fc33b9c235780d3aa90357d20dd6108b92be544427bea197dd"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:78988ed190206672da0f5d50c61afef8f67daa718d614377dcd5e3ed85ab4a99"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:210c8fcfeff90514b7133010bf14e3bad652c8efde6b20e00c43854bf94fa5a6"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-win32.whl", hash = "sha256:a49e0161897901d1ac9c4a79984b8410f450565bbad64dbfcbf76152743a0cdb"}, + {file = "ruamel.yaml.clib-0.2.6-cp37-cp37m-win_amd64.whl", hash = "sha256:bf75d28fa071645c529b5474a550a44686821decebdd00e21127ef1fd566eabe"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:a32f8d81ea0c6173ab1b3da956869114cae53ba1e9f72374032e33ba3118c233"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7f7ecb53ae6848f959db6ae93bdff1740e651809780822270eab111500842a84"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:61bc5e5ca632d95925907c569daa559ea194a4d16084ba86084be98ab1cec1c6"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-win32.whl", hash = "sha256:89221ec6d6026f8ae859c09b9718799fea22c0e8da8b766b0b2c9a9ba2db326b"}, + {file = "ruamel.yaml.clib-0.2.6-cp38-cp38-win_amd64.whl", hash = "sha256:31ea73e564a7b5fbbe8188ab8b334393e06d997914a4e184975348f204790277"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:dc6a613d6c74eef5a14a214d433d06291526145431c3b964f5e16529b1842bed"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:1866cf2c284a03b9524a5cc00daca56d80057c5ce3cdc86a52020f4c720856f0"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:1b4139a6ffbca8ef60fdaf9b33dec05143ba746a6f0ae0f9d11d38239211d335"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-win32.whl", hash = "sha256:3fb9575a5acd13031c57a62cc7823e5d2ff8bc3835ba4d94b921b4e6ee664104"}, + {file = "ruamel.yaml.clib-0.2.6-cp39-cp39-win_amd64.whl", hash = "sha256:825d5fccef6da42f3c8eccd4281af399f21c02b32d98e113dbc631ea6a6ecbc7"}, + {file = "ruamel.yaml.clib-0.2.6.tar.gz", hash = "sha256:4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd"}, +] +safety = [ + {file = "safety-2.3.1-py3-none-any.whl", hash = "sha256:8f098d12b607db2756886280e85c28ece8db1bba4f45fc5f981f4663217bd619"}, + {file = "safety-2.3.1.tar.gz", hash = "sha256:6e6fcb7d4e8321098cf289f59b65051cafd3467f089c6e57c9f894ae32c23b71"}, +] setuptools = [ {file = "setuptools-65.5.0-py3-none-any.whl", hash = "sha256:f62ea9da9ed6289bfe868cd6845968a2c854d1427f8548d52cae02a42b4f0356"}, {file = "setuptools-65.5.0.tar.gz", hash = "sha256:512e5536220e38146176efb833d4a62aa726b7bbff82cfbc8ba9eaa3996e0b17"}, ] +toml = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] +urllib3 = [ + {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, + {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, +] zope-interface = [ {file = "zope.interface-5.5.0-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:2cb3003941f5f4fa577479ac6d5db2b940acb600096dd9ea9bf07007f5cab46f"}, {file = "zope.interface-5.5.0-cp27-cp27m-win32.whl", hash = "sha256:8c791f4c203ccdbcda588ea4c8a6e4353e10435ea48ddd3d8734a26fe9714cba"}, diff --git a/practice/ALTokarev7/1/game.py b/practice/ALTokarev7/1/game.py index f3fffb4..298fe53 100644 --- a/practice/ALTokarev7/1/game.py +++ b/practice/ALTokarev7/1/game.py @@ -12,9 +12,12 @@ 'd': 1, } -CONTROL_BUTTONS = ("w", "s","a","d") +CONTROL_BUTTONS = ("w", "s", "a", "d") + +TRUE_POS = (1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, "x" + ) -TRUE_POS = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,"x") def shuffle_field(): shuffled_tiles = list(TRUE_POS) @@ -23,51 +26,57 @@ def shuffle_field(): return shuffled_tiles + def print_field(field): for i in range(4): print( - field[i*4],'\t', - field[i*4 + 1],'\t', - field[i*4 + 2],'\t', + field[i*4], '\t', + field[i*4 + 1], '\t', + field[i*4 + 2], '\t', field[i*4 + 3], ) return + def is_game_finished(field): if tuple(field) == TRUE_POS: return True - + return False + def perform_move(field, key): empty_ind = field.index("x") new_ind = empty_ind + MOVES[key] if new_ind < 0 or new_ind > (len(field) - 1): return None - if key == 'a' or key =='d': + if key == 'a' or key == 'd': if (empty_ind // 4) != (new_ind // 4): - return None - + return None + field[empty_ind], field[new_ind] = field[new_ind], field[empty_ind] return field + def handle_user_input(): move = input("choose you move: ") while move not in CONTROL_BUTTONS: - print("Enter only : 'w', 's','a','d'") + print("Enter only : 'w', 's','a','d'") move = input("choose you move: ") return move + def main(): field = shuffle_field() while not is_game_finished(field): print_field(field) if perform_move(field, handle_user_input()) is None: print("Invalid move!!!") - + print("You`re champion!!!") + if __name__ == '__main__': main()