CoolFace
Apppublic

TangibleAI/mathtext-fastapi

sourceHugging Faceagpl-3.0updated 3y agoView on Hugging Face
1likes
hints.py32 linesDownload Raw Back to quiz
1import random2 3 4def generate_hint(question_nums, right_answer, right_answers, wrong_answers, level, hints_used):5    ord_num = question_nums[1]  # ordinal number6    equation = right_answer - 2 * ord_num - 17    min_num = equation if equation > 0 else 08    seq_before = " ".join(9        [str(num) for num in range(right_answer - ord_num, min_num, -ord_num)][::-1]10    )  # sequence before right answer11    seq_after = " ".join(12        [str(num) for num in range(right_answer + ord_num, right_answer + 2 * ord_num + 1, ord_num)]13    )  # sequence after right answer14    hints = [15        f"What number will fill the gap in a sequence {seq_before} ... {seq_after}?",16        f"What number is {ord_num} in the account after {right_answer - ord_num}?",17        f"What number is {ord_num} in the account before {right_answer + ord_num}?",18        f"What number is greater than {right_answer - 1} and less than {right_answer + 1}?"19    ]20    rand_hint = random.choice(hints)21    hints_used += 122 23    output = {24        "text": rand_hint,25        "question_numbers": question_nums,26        "right_answer": right_answer,27        'number_correct': right_answers,28        'number_incorrect': wrong_answers,29        'level': level,30        "hints_used": hints_used31    }32    return output