INNER CODE UNIT · Python
print_qa
AMontgomerie/question_generator · questiongenerator.py:394
def print_qa(qa_list: List[Mapping[str, str]], show_answers: bool = True) -> None:
"""Formats and prints a list of generated questions and answers."""
for i in range(len(qa_list)):
# wider space for 2 digit q nums
space = " " * int(np.where(i < 9, 3, 4))
print(f"{i + 1}) Q: {qa_list[i]['question']}")
answer = qa_list[i]["answer"]
# print a list of multiple choice answers
if type(answer) is list:
if show_answers:
print(
f"{space}A: 1. {answer[0]['answer']} "
f"{np.where(answer[0]['correct'], '(correct)', '')}"