diff --git a/.gitignore b/.gitignore index 9f34fb6..ac39565 100644 --- a/.gitignore +++ b/.gitignore @@ -159,8 +159,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -dict.py +tmp/ repo.py -remark.py -guess_.py diff --git a/guess_.py b/guess_.py deleted file mode 100644 index 26812ad..0000000 --- a/guess_.py +++ /dev/null @@ -1,33 +0,0 @@ -import itertools - -def all_combinations(alphabet, max_length): - """Генерирует все комбинации длиной от 1 до max_length""" - all_combos = [] - for length in range(1, max_length + 1): - combos = itertools.product(alphabet, repeat=length) - all_combos.extend([''.join(combo) for combo in combos]) - return all_combos - -russian_lower = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя' -def vectorize(word, combinations): - vector = [] - if len(word) == 1: - return None - last = None - for curr in word: - if not last: - last = curr - continue - pair = last + curr - indx = combinations.index(pair) - vector.append(indx) - return vector - - -word = 'маме' -combinations = all_combinations(russian_lower, 2) -result = vectorize(word, combinations) - -print("Все комбинации длиной 1-2:") -print(combinations) -print("Вектор:", result) diff --git a/lesson_5/code/db.py b/lesson_5/code/db.py new file mode 100644 index 0000000..05fbbe9 --- /dev/null +++ b/lesson_5/code/db.py @@ -0,0 +1,2 @@ +DICT_DEFENITION_WORD = {'инкапсуляция': 'сокрытие реализации', + 'полиморфизм': 'изменение поведение при наследовании' } \ No newline at end of file diff --git a/lesson_5/code/ya_kube.py b/lesson_5/code/ya_kube.py new file mode 100644 index 0000000..4cfb706 --- /dev/null +++ b/lesson_5/code/ya_kube.py @@ -0,0 +1,102 @@ +import random +import uuid +import datetime +from lesson_5.code.db import DICT_DEFENITION_WORD + +name = input("Введите имя:") + +def print_menu(): + print(""" + 1. Начать игру + 2. Сохранить игру + 3. Загрузить игру + 4. Выход из игры + 5. Настройки + """) + +print_menu() +num = int(input("Пункт меню:")) + + +def generate_key() -> str: + keys = list(DICT_DEFENITION_WORD.keys()) + random.shuffle(keys) + return keys.pop() + + +def save_game(id_session, word, mask): + # dt, id_session, name, word, mask + f = open("save_game.csv", "at") + dt = datetime.datetime.now() + mask = "".join(mask) + str = f"{dt}|{id_session}|{name}|{word}|{mask}" + f.write(str) + f.close() + print("Сохранил игру!") + + +def load_game(): + f = open("save_game.csv", "tr") + indx = 0 + list_str= f.readlines() + for csv_str in list_str: + if name in csv_str: + print(indx, ") ", csv_str) + indx += 1 + indx_load = int(input("Введите номер:")) + sg = list_str[indx_load].split("|") + key = sg[3] + mask = sg[4] + session_uuid = sg[1] + print(session_uuid,key, list(mask)) + start_game(session_uuid,key.strip(), list(mask)) + exit(0) + + +def start_game(session_uuid, key, mask ): + + print(DICT_DEFENITION_WORD[key]) + print(mask) + while '#' in mask: + alfa = input("Введите букву:") + if alfa == "2": + print("Сохранение игры!") + save_game(session_uuid, key, mask) + cnt = 0 + for i in list_word: + if alfa == i: + mask[cnt] = alfa + cnt += 1 + continue + cnt += 1 + else: + print(mask) + +match num: + case 1: + key = generate_key() + list_word = list(key) + mask = ['#'] * len(key) + session_uuid = uuid.uuid4() + start_game(session_uuid,key,mask) + # print('The UUID is: ' + str(session_uuid)) + case 2: + pass + case 3: + load_game() + case 4: + print(f"Спасибо {name} за игру! Заходи еще! ") + pass + + + + + + + + + + + + + diff --git a/lesson_5/home_task/task19.py b/lesson_5/home_task/task19.py new file mode 100644 index 0000000..c5a9709 --- /dev/null +++ b/lesson_5/home_task/task19.py @@ -0,0 +1,13 @@ +#todo: Требуется создать csv-файл «algoritm.csv» со следующими столбцами: +# id) - номер по порядку (от 1 до 10); +# значение из списка algoritm + +algoritm = [ "C4.5" , "k - means" , "Метод опорных векторов" , + "Apriori", "EM", "PageRank" , "AdaBoost", "kNN" , + "Наивный байесовский классификатор", "CART" ] + +# Каждое значение из списка должно находится на отдельной строке. +# Пример файла algoritm.csv: +1) "C4.5" +2) "k - means" +..... \ No newline at end of file diff --git a/lesson_5/home_task/task20.py b/lesson_5/home_task/task20.py new file mode 100644 index 0000000..db8a85c --- /dev/null +++ b/lesson_5/home_task/task20.py @@ -0,0 +1,14 @@ +#todo: Выведите все строки данного файла в обратном порядке, допишите их в этот же файл. +# Для этого считайте список всех строк при помощи метода readlines(). + +#Содержимое файла inverted_sort.txt +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. + +# Результат +Complex is better than complicated. +Simple is better than complex. +Explicit is better than implicit. +Beautiful is better than ugly. \ No newline at end of file diff --git a/lesson_5/home_task/task21.py b/lesson_5/home_task/task21.py new file mode 100644 index 0000000..476325b --- /dev/null +++ b/lesson_5/home_task/task21.py @@ -0,0 +1,58 @@ +#todo: Задан шаблон config_default.txt, где каждому в текстовом файле параметру +# нужно сопоставить данные для подстановки. + +# Содержимое файла config_default.txt +# Конфигурация приложения. +app_name = ? +version = ? +debug = ? + +# Настройки базы данных +db_host = ? +db_port = ? +db_name = ? +db_user = ? +db_password = ? + +# Настройки API +api_key = ? +api_secret = ? +base_url = ? + +# Пути +log_file = ? +data_dir = ? +temp_dir = ? + + +# Данные для подстановки +config_values = { + 'app_name': 'NextGen', + 'version': '1.0.0', + 'debug': True, + 'db_host': 'localhost', + 'db_port': 5432, + 'db_name': 'my_database', + 'db_user': 'admin', + 'db_password': 'secret123', + 'api_key': 'ak_123456789', + 'api_secret': 'sk_987654321', + 'base_url': 'https://api.example.com', + 'log_file': '/var/log/app.log', + 'data_dir': '/opt/app/data', + 'temp_dir': '/tmp/app', + 'max_workers': 10, + 'timeout': 30, + 'retry_attempts': 3 +} + +# В итоге вместо "?" должны подставиться значения и получиться файл config.txt: + +# Конфигурация приложения +app_name = "NextGen" +version = '1.0.0' +debug = True + +# Настройки базы данных +db_host = 5432 +..... \ No newline at end of file diff --git a/lesson_5/home_task/task22.py b/lesson_5/home_task/task22.py new file mode 100644 index 0000000..9453729 --- /dev/null +++ b/lesson_5/home_task/task22.py @@ -0,0 +1,8 @@ +#todo: Модифицировать программу таким образом чтобы она выводила +# приветствие "Hello", которое только что записали в файл text.txt + +f = open("text.txt", "w+t") +f.write("Hello\n") +# Ваше решение. + +f.close() \ No newline at end of file diff --git a/lesson_5/home_task/task23.py b/lesson_5/home_task/task23.py new file mode 100644 index 0000000..142e5b9 --- /dev/null +++ b/lesson_5/home_task/task23.py @@ -0,0 +1,5 @@ +# todo: Исправить ошибку в коде игры ../code/ya_kube.py + +from lesson_5.code import ya_kube + + diff --git a/lesson_5/manual/lection_IO.pdf b/lesson_5/manual/lection_IO.pdf new file mode 100644 index 0000000..0c424a0 Binary files /dev/null and b/lesson_5/manual/lection_IO.pdf differ