예제 #1
0
    suffix = ""

    for group_id, mylist in enumerate(lists):
        group = str(group_id)
        for type_ in lists[group_id]:
            mycounter += 1
            if mycounter % trim != 0:
                continue

            q_problem_str = question_problem.format(str(type_))
            result = {}
            try:
                exec(prefix + q_problem_str + suffix, result)
                if type_ == "/":
                    result['q'] = "0.0"
            except Exception as e:
                result = {'q': type(e).__name__}

            yield Question(group, type_, result['q'])


wrong_answers0 = [Answer("1"), Answer("ZeroDivisionError")]

generator.extra_answers({GROUP0: wrong_answers0})
#generator.extra_answers({GROUP0:wrong_answers0,GROUP1:wrong_answers1})
#generator.enable_debugging()
generator.sort_questions_by_difficulty()
generator.ignore_duplicate_answers()
generator.ignore_duplicate_questions()
generator.generate(get_questions())
예제 #2
0
파일: skabelon.py 프로젝트: sci2u/api
        plt.close()


# ----------------------------------------------------------------------------


def get_functions(var):
    # Denne generator laver alle spørgsmålene.
    yield exp(a*var)
    yield ln(a*var)
    yield a*(var**4)
    yield a/(var**4)
    yield sqrt(1+(var**4))
    yield (1+var)**a
    yield exp(a*var**2)


def get_questions():
    # Sætter spørgsmålsgeneratoren i gang, og leverer resultatet til Question
    # klassen.
    for func in get_functions(x):
        yield Question(func, x)


generator.enable_debugging()
generator.ignore_duplicate_answers()
# argumentet i save_to() er den folder, du ønsker at gemme i (og er samtidig
# titlen på første linje i info.txt
generator.generate_quiz(get_questions())