lesson 5
This commit is contained in:
parent
f238c8e59f
commit
56394b7aec
4
.gitignore
vendored
4
.gitignore
vendored
@ -159,8 +159,6 @@ cython_debug/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# 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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
.idea/
|
.idea/
|
||||||
dict.py
|
tmp/
|
||||||
repo.py
|
repo.py
|
||||||
remark.py
|
|
||||||
|
|
||||||
guess_.py
|
|
||||||
|
|||||||
33
guess_.py
33
guess_.py
@ -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)
|
|
||||||
2
lesson_5/code/db.py
Normal file
2
lesson_5/code/db.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
DICT_DEFENITION_WORD = {'инкапсуляция': 'сокрытие реализации',
|
||||||
|
'полиморфизм': 'изменение поведение при наследовании' }
|
||||||
102
lesson_5/code/ya_kube.py
Normal file
102
lesson_5/code/ya_kube.py
Normal file
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
13
lesson_5/home_task/task19.py
Normal file
13
lesson_5/home_task/task19.py
Normal file
@ -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"
|
||||||
|
.....
|
||||||
14
lesson_5/home_task/task20.py
Normal file
14
lesson_5/home_task/task20.py
Normal file
@ -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.
|
||||||
58
lesson_5/home_task/task21.py
Normal file
58
lesson_5/home_task/task21.py
Normal file
@ -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
|
||||||
|
.....
|
||||||
8
lesson_5/home_task/task22.py
Normal file
8
lesson_5/home_task/task22.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#todo: Модифицировать программу таким образом чтобы она выводила
|
||||||
|
# приветствие "Hello", которое только что записали в файл text.txt
|
||||||
|
|
||||||
|
f = open("text.txt", "w+t")
|
||||||
|
f.write("Hello\n")
|
||||||
|
# Ваше решение.
|
||||||
|
|
||||||
|
f.close()
|
||||||
5
lesson_5/home_task/task23.py
Normal file
5
lesson_5/home_task/task23.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# todo: Исправить ошибку в коде игры ../code/ya_kube.py
|
||||||
|
|
||||||
|
from lesson_5.code import ya_kube
|
||||||
|
|
||||||
|
|
||||||
BIN
lesson_5/manual/lection_IO.pdf
Normal file
BIN
lesson_5/manual/lection_IO.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user