From b63ff7e1e75a692e2ed609a721a5494b57fc2e86 Mon Sep 17 00:00:00 2001 From: Olga Bugrova Date: Sat, 8 Jan 2022 19:51:26 +0300 Subject: [PATCH 1/6] homework lec.1 --- Practice/obugrova/pep8task.py | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Practice/obugrova/pep8task.py diff --git a/Practice/obugrova/pep8task.py b/Practice/obugrova/pep8task.py new file mode 100644 index 0000000..3b05ddf --- /dev/null +++ b/Practice/obugrova/pep8task.py @@ -0,0 +1,69 @@ +import sys +import os +import hashlib +import ast +import argparse +from time import * + + +class shuffler: + + def __init__(self): + self.map = {} + + def rename(self, dirname, output): + mp3s = [] # лишние отступы + for root, directories, files in os.walk(dirname): + for file in files: + if file[-3:] == '.mp3': + mp3s.append([root, file]) # лишний отступ + for path, mp3 in mp3s: + hashname = self.generateName() + '.mp3' + self.map[hashname] = mp3 + os.rename(path + '/' + mp3), path + '/' + hashname)) + f = open(output, 'r') + f.write(str(self.map)) + + def restore(self, dirname, restore_path): + with open(filename, '+') as f: # лишние отступы + self.map = ast.literal_eval(f.read()) + mp3s = [] + for root, directories, files in os.walk(dirname): + for file in files: + if file[-3:] == '.mp3': + mp3s.append({root, file}) + for path, hashname in mp3s: + os.rename(path + '/' + hashname, path + '/' + self.map[hashname])) + os.remove(restore_path) # + + def generateName(self, seed=time()): + return hashlib.md5(str(seed)).hexdigest() + + +def parse_arguments(): + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(dest='subcommand', help='subcommand help') + rename_parser = subparsers.add_parser('rename', help='rename help') + rename_parser.add_argument('dirname') + rename_parser.add_argument('-o', '--output', help='path to a file where restore map is stored') + restore_parser = subparsers.add_parser('restore', help="command_a help") + restore_parser.add_argument('dirname') + restore_parser.add_argument('restore_map') + args = parser.parse_args() + return args +# не хватает строки между функциями +def main(): + args = parse_arguments() + Shuffler = shuffler() + if args.subcommand == 'rename': + if args.output: # лишние отступы + Shuffler.rename(args.dirname, 'restore.info') + else: # лишние отступы + Shuffler.rename(args.dirname, args.output) + elif args.subcommand == 'restore': + Shuffler.restore(args.dirname, args.restore_map) + else: + sys.exit() + + +main() From 8eb88028d90f43d0ebdcc054df9a0ac0fe451191 Mon Sep 17 00:00:00 2001 From: Olga Bugrova Date: Sun, 9 Jan 2022 01:07:36 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9B=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=202,?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=201,=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/obugrova/lec2_ex.1,2.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Practice/obugrova/lec2_ex.1,2.py diff --git a/Practice/obugrova/lec2_ex.1,2.py b/Practice/obugrova/lec2_ex.1,2.py new file mode 100644 index 0000000..e42f51d --- /dev/null +++ b/Practice/obugrova/lec2_ex.1,2.py @@ -0,0 +1,14 @@ +def biggest (a, b): + if a > b: + print (a) + else: + print (b) +biggest (2, 3) + +def returnbiggest (a, b): + if a > b: + return a + else: + return b +c = returnbiggest(8, 7) +print(c) \ No newline at end of file From 073c535f1adec2f2a6487d9bf763d86e8688f22e Mon Sep 17 00:00:00 2001 From: Olga Bugrova Date: Sun, 16 Jan 2022 17:27:34 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9B=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=202,?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/obugrova/tanks.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Practice/obugrova/tanks.py diff --git a/Practice/obugrova/tanks.py b/Practice/obugrova/tanks.py new file mode 100644 index 0000000..66bc7e8 --- /dev/null +++ b/Practice/obugrova/tanks.py @@ -0,0 +1,45 @@ +class Tank: + x = 0 + y = 0 + color = 0 + speed = 1 + + def Move (self, direction): + if direction == "up" and y < 20: + y = y - speed + if direction == "right" and x < 20: + x = x - speed + if direction == "down" and y > 0: + y = y + speed + if direction == "left" and x > 0: + x = x + speed + print(f"Moving to (x).(y)") + + def Shoot(self): + print("shooting") + + +class Map: + # Массив ячеек + width = 20 + length = 20 + + +class Cell: + wall = 0 +''' +Поле состоит из клеток +Клетка либо пуста, либо содержит препятствие +''' + + +class Shot: + direction # выстрел имеет направление + distance # дистанция, которую он преодолевает + color + speed + coordinate + + def Move(self): + + def Hit(self): # Выстрел поразил цель или нет \ No newline at end of file From 081466b63be12baa6cef44b0ec74e846e6f02193 Mon Sep 17 00:00:00 2001 From: Olga Bugrova Date: Sun, 16 Jan 2022 17:28:15 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9B=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=202,?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/obugrova/lec.3_Palindrome.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Practice/obugrova/lec.3_Palindrome.py diff --git a/Practice/obugrova/lec.3_Palindrome.py b/Practice/obugrova/lec.3_Palindrome.py new file mode 100644 index 0000000..5ce8ff4 --- /dev/null +++ b/Practice/obugrova/lec.3_Palindrome.py @@ -0,0 +1,16 @@ +w = input("Введите слово: ") +w = w.lower() + +def palindrome(w): + if len(w) == 1 or len(w) == 0: + return 0 + if w[0] == w[-1]: + return palindrome(w[1:-1]) + else: + return 1 + +test = palindrome(w) +if test == 0: + print("Это палиндром") +elif test == 1: + print("Введённое слово не является палиндромом") \ No newline at end of file From 62bb0e13db2658a65946bc9105e9611c31dd4b17 Mon Sep 17 00:00:00 2001 From: Olga Bugrova Date: Sun, 16 Jan 2022 17:29:16 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9B=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=202,?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=201,=202=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/obugrova/lec2_ex.1,2.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Practice/obugrova/lec2_ex.1,2.py b/Practice/obugrova/lec2_ex.1,2.py index e42f51d..a2ef290 100644 --- a/Practice/obugrova/lec2_ex.1,2.py +++ b/Practice/obugrova/lec2_ex.1,2.py @@ -1,14 +1,17 @@ -def biggest (a, b): +def biggest(a, b): if a > b: - print (a) + print(a) else: - print (b) -biggest (2, 3) + print(b) +biggest(2, 3) -def returnbiggest (a, b): + +def returnbiggest(a, b): if a > b: return a else: return b + + c = returnbiggest(8, 7) -print(c) \ No newline at end of file +print(c) From 16ddbc8dad62c5bd5adf21cdb83317ee086dae40 Mon Sep 17 00:00:00 2001 From: Olga Bugrova Date: Wed, 26 Jan 2022 18:09:48 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9B=D0=B5=D0=BA=D1=86=D0=B8=D1=8F=204,?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Practice/obugrova/lec_4, ex_2.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Practice/obugrova/lec_4, ex_2.py diff --git a/Practice/obugrova/lec_4, ex_2.py b/Practice/obugrova/lec_4, ex_2.py new file mode 100644 index 0000000..cb56386 --- /dev/null +++ b/Practice/obugrova/lec_4, ex_2.py @@ -0,0 +1,4 @@ +num = int(input("Введите пятизначное число: ")) +for i in range(4, -1, -1): + n = (num % 10**(i + 1)) // 10**i + print(5 - i, "цифра равна", n) \ No newline at end of file