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 diff --git a/Practice/obugrova/lec2_ex.1,2.py b/Practice/obugrova/lec2_ex.1,2.py new file mode 100644 index 0000000..a2ef290 --- /dev/null +++ b/Practice/obugrova/lec2_ex.1,2.py @@ -0,0 +1,17 @@ +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) 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 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() 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