exam module

Functions

exam.make_answer_key(exam)

Creates an answer key for the given multiple-choice exam.

Parameters:

exam (mc_exam) – An exam object containing elements, options, and a correct_string to identify correct answers.

Returns:

A dictionary representing the answer key.

Return type:

dict

Classes

class exam.mc_question

Defines a class for storing and managing the content of a multiple-choice question.

__init__(question_string=None, correct_string=None)

Initializes an mc_question instance.

Parameters:
  • question_string (str, optional) – The full content of the multiple-choice question, including options. Defaults to None.

  • correct_string (str, optional) – The marker indicating the correct answer. Defaults to None.

shuffle_options(rng)

Shuffles the options of the question if shuffling is desired.

Parameters:

rng (numpy.random.Generator) – A random number generator for shuffling.

Returns:

A new mc_question instance with shuffled options.

Return type:

mc_question

add_periods(include_equations=True, correct_string=None)

Adds periods to the end of each option if not already present.

Parameters:
  • include_equations (bool, optional) – Whether to include periods for options ending with equations. Defaults to True.

  • correct_string (str, optional) – The marker for the correct answer. Defaults to None.

capitalize_first(correct_string=None)

Capitalizes the first letter of each option.

Parameters:

correct_string (str, optional) – The marker for the correct answer. Defaults to None.

class exam.mc_group

Defines a class for storing and managing a group of multiple-choice questions.

__init__(group_lines, correct_string)

Initializes an mc_group instance.

Parameters:
  • group_lines (list) – Lines from a LaTeX file between begin{mcquestions} and end{mcquestions}.

  • correct_string (str) – The marker indicating the correct answer for questions in the group.

shuffle_questions(rng)

Shuffles the order of questions within the group.

Parameters:

rng (numpy.random.Generator) – A random number generator for shuffling.

Returns:

A new mc_group instance with shuffled questions.

Return type:

mc_group

shuffle_options(rng)

Shuffles the options for each question in the group.

Parameters:

rng (numpy.random.Generator) – A random number generator for shuffling.

Returns:

A new mc_group instance with shuffled options for each question.

Return type:

mc_group