/
Suplin3
/
TestsCompiler
Обзор
Документация
Войти
/
Suplin3
/
TestsCompiler
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
main.py
75 строк
3 KB
Suplin3
add files
24 сен 2024, 23:15
24 сен 2024, 23:15
aff9697
Код
Авторство
О чём код?
import rich from rich.panel import Panel from rich.prompt import Prompt import random commands_panel = Panel("1 - Создать варианты.\n2 - Выход.", title="Команды", expand=False) try: open("questions.txt", "r").close() open("answers.txt", "r").close() except FileNotFoundError: open("questions.txt", "w").close() open("answers.txt", "w").close() while True: rich.print(commands_panel) command = input("Введите команду>>") with open("questions.txt", "r", encoding="utf-8") as qfile: text = qfile.read() groups_count = len(text.split("--!--")) rich.print("[blue]Определено порядков вопросов:", groups_count) answers = [] with open("answers.txt", "r", encoding="utf-8") as afile: for line in afile.readlines(): answers.append(line.strip()) afile.close() rich.print(f"[blue]Всего ответов: {len(answers)}") questions_count = 0 questions = [] for qg in text.split("--!--"): group = [] for q in qg.split("---"): questions_count += 1 group.append([q.strip(), answers[questions_count - 1]]) questions.append(group) rich.print(f"[blue]Всего вопросов: {questions_count}") qfile.close() if command == "1": qing = Prompt.ask("Введите количество вопросов для каждого порядка", default=("1 " * groups_count).strip()) variants = int(Prompt.ask("Введите количество вариантов", default="4")) with open("output_questions.txt", "w") as qfile: with open("output_answers.txt", "w") as afile: for j in range(variants): qfile.write(f"--[Вариант {j + 1}]--\n") afile.write(f"--[Вариант {j + 1}]--\n") for i, group in enumerate(questions): current_questions = [] for qi in range(int(qing.split(" ")[i])): while 1: random_question = random.choice(group) if random_question in current_questions: continue else: current_questions.append(random_question) break qfile.write(random_question[0] + "\n\n") afile.write(random_question[1] + "\n") afile.close() qfile.close() rich.print("[green]Успешно!") input() break elif command == "2": exit() else: rich.print(":warning:[red blink bold] Неизвестная команда")