Problem Bank Helpers
- problem_bank_helpers.problem_bank_helpers.create_data2() defaultdict[source]
- problem_bank_helpers.problem_bank_helpers.sigfigs(x: str) int[source]
Returns the number of significant digits in a number represented as a string.
This takes into account strings formatted in
1.23e+3format and even strings such as123.450. This has a limit of 16 sigfigs, which can be increased but doesn’t seem practical- Parameters:
x (str) – The number as a string
- Returns:
The number of significant figures in the number
- Return type:
Examples
>>> sigfigs("1.23e+3") 3 >>> sigfigs("123.450") 6
- problem_bank_helpers.problem_bank_helpers.round_sig(x: float, sig: int) float[source]
Round a number to a specified number of significant digits.
- problem_bank_helpers.problem_bank_helpers.roundp(*args, **kwargs)[source]
Wrapper function for the sigfig.round package. Also deals with case if requested sig figs is more than provided.
- problem_bank_helpers.problem_bank_helpers.num_as_str(num, digits_after_decimal=2)[source]
Rounds numbers properly to specified digits after decimal place
- problem_bank_helpers.problem_bank_helpers.sign_str(number)[source]
Returns the sign of the input number as a string.
- Parameters:
sign (number) – A number, float, etc…
- Returns:
Either ‘+’ or ‘-’
- Return type:
- problem_bank_helpers.problem_bank_helpers.automatic_feedback(data, string_rep=None, rtol=None)[source]
- problem_bank_helpers.problem_bank_helpers.ErrorCheck(errorCheck, subVariable, Variable, LaTeXstr, tolerance)[source]
- problem_bank_helpers.problem_bank_helpers.backticks_to_code_tags(data: dict) None[source]
Converts backticks to <code> tags, and code fences to <pl-code> tags for a filled PrairieLearn question data dictionary. Note: this only makes replacements multiple choice (and other similar question) answer options.
- Parameters:
data (dict) – The filled PrairieLearn question data dictionary
- problem_bank_helpers.problem_bank_helpers.base64_encode(s: str) str[source]
Encode a regular string into a base64 representation to act as a file for prarielearn to store
- problem_bank_helpers.problem_bank_helpers.base64_decode(f: str) str[source]
Decode a base64 string (which is a file) from prairielearn into a useable string
- problem_bank_helpers.problem_bank_helpers.string_to_pl_user_file(string: str, data: dict, name: str = 'user_code.py') None[source]
Encode a string to base64 and add it as the user submitted code file
- problem_bank_helpers.problem_bank_helpers.create_html_table(table: list[list[str]], width: str = '100%', first_row_is_header: bool = True, first_col_is_header: bool = True, wrap_header_latex: bool = False, wrap_nonheader_latex: bool = False) str[source]
Convert a python table to HTML
Example usage:
server.py: data[“params”][“table1”] = pbh.convert_markdown_table([[“a”, “b”, “c”], [“x”, “1”]], wrap_nonheader_latex=True)
markdown: {{{ params.table1 }}}
- Parameters:
table (list) – A list of lists representing the table
width (str, optional) – The width of the table. Ex. “100%”, “500px”, etc.
first_row_is_header (bool, optional) – Whether the first row is a header. Defaults to True.
first_col_is_header (bool, optional) – Whether the first column is a header. Defaults to True.
wrap_nonheader_latex (bool, optional) – Whether to wrap all non-header table cells in $ for LaTeX. Defaults to False.
wrap_header_latex (bool, optional) – Whether to wrap all header table cells in $ for LaTeX. Defaults to False.
- Returns:
The HTML representation of the table
- Return type:
- problem_bank_helpers.problem_bank_helpers.template_mc(data: dict, part_num: int, choices: dict) None[source]
Adds multiple choice to data from dictionary
- Parameters:
Example
>>> options = { ... "option1 goes here": ["correct", "Nice work!"], ... "option2 goes here": ["Incorrect", "Incorrect, try again!"], ... ... ... } >>> template_mc(data2, 1, options)