You've already forked HeurAMS-legacy
style: 代码格式化
This commit is contained in:
@@ -2,15 +2,12 @@
|
||||
from .base import BasePuzzle
|
||||
import random
|
||||
|
||||
|
||||
class MCQPuzzle(BasePuzzle):
|
||||
"""选择题谜题生成器"""
|
||||
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mapping: dict,
|
||||
jammer: list,
|
||||
max_riddles_num: int = 2,
|
||||
prefix: str = ""
|
||||
self, mapping: dict, jammer: list, max_riddles_num: int = 2, prefix: str = ""
|
||||
):
|
||||
self.prefix = prefix
|
||||
self.mapping = mapping
|
||||
@@ -29,18 +26,16 @@ class MCQPuzzle(BasePuzzle):
|
||||
self.answer = ["无答案"]
|
||||
self.options = []
|
||||
return
|
||||
|
||||
|
||||
num_questions = min(self.max_riddles_num, len(self.mapping))
|
||||
questions = random.sample(list(self.mapping.items()), num_questions)
|
||||
puzzles = []
|
||||
answers = []
|
||||
all_options = []
|
||||
|
||||
|
||||
for question, correct_answer in questions:
|
||||
options = [correct_answer]
|
||||
available_jammers = [
|
||||
j for j in self.jammer if j != correct_answer
|
||||
]
|
||||
available_jammers = [j for j in self.jammer if j != correct_answer]
|
||||
if len(available_jammers) >= 3:
|
||||
selected_jammers = random.sample(available_jammers, 3)
|
||||
else:
|
||||
@@ -50,14 +45,14 @@ class MCQPuzzle(BasePuzzle):
|
||||
puzzles.append(question)
|
||||
answers.append(correct_answer)
|
||||
all_options.append(options)
|
||||
|
||||
|
||||
question_texts = []
|
||||
for i, puzzle in enumerate(puzzles):
|
||||
question_texts.append(f"{self.prefix}:\n {i+1}. {puzzle}")
|
||||
|
||||
|
||||
self.wording = question_texts
|
||||
self.answer = answers
|
||||
self.options = all_options
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.wording}\n正确答案: {', '.join(self.answer)}"
|
||||
return f"{self.wording}\n正确答案: {', '.join(self.answer)}"
|
||||
|
||||
Reference in New Issue
Block a user