tex2lambda.api.question.Question#

class tex2lambda.api.question.Question(title: str = '', parts: list[tex2lambda.api.part.Part] = <factory>, images: list[str] = <factory>, _main_text: str = '', _last_part: dict[str, int] = <factory>)[source]#

Bases: object

A full question as represented on Lambda Feedback.

Each question has a title and is composed of a list of parts.

Examples

>>> from tex2lambda.api.question import Question
>>> Question(title="Some title", _main_text="Some text")
Question(title='Some title', parts=[], images=[], _main_text='Some text')
__init__(title: str = '', parts: list[tex2lambda.api.part.Part] = <factory>, images: list[str] = <factory>, _main_text: str = '', _last_part: dict[str, int] = <factory>) None#

Methods

__init__([title, parts, images, _main_text, ...])

add_part_text(elem)

Either adds a new part with the given text or modifies the first part with no text.

add_solution(elem)

Adds a worked solution to all question parts without one, or inserts a new empty part with the solution if all parts already have a solution.

Attributes

main_text

Main top-level question text.

title

parts

images

add_part_text(elem: Element | str) None[source]#

Either adds a new part with the given text or modifies the first part with no text.

Parameters:

elem – A string or panflute element denoting what the part text should be.

Examples

>>> from tex2lambda.api.question import Question
>>> question = Question()
>>> question.add_part_text("part a")
>>> question.add_solution("part a solution")
>>> question
Question(title='', parts=[Part(text='part a', worked_solution='part a solution')], images=[], _main_text='')
>>> # Supports adding the answer first.
>>> question.add_solution("part b solution")
>>> question.add_part_text("part b")
>>> question
Question(title='', parts=[Part(text='part a', worked_solution='part a solution'), Part(text='part b', worked_solution='part b solution')], images=[], _main_text='')
add_solution(elem: Element | str) None[source]#

Adds a worked solution to all question parts without one, or inserts a new empty part with the solution if all parts already have a solution.

Args:

elem: A string or panflute element denoting a worked solution.

Examples:
>>> from tex2lambda.api.question import Question
>>> question = Question()
>>> question.add_part_text("part a")
>>> question.add_solution("part a solution")
>>> question
Question(title='', parts=[Part(text='part a', worked_solution='part a solution')], images=[], _main_text='')
>>> question.add_part_text("part b")
>>> question.add_part_text("part c")
>>> question.add_solution("Solution for b")
>>> # Note that since c doesn't have a solution, it's set to b's solution
>>> question
Question(title='', parts=[Part(text='part a', worked_solution='part a solution'), Part(text='part b', worked_solution='Solution for b'), Part(text='part c', worked_solution='Solution for b')], images=[], _main_text='')
>>> question.add_solution("We now have a solution for c!")
>>> question
Question(title='', parts=[Part(text='part a', worked_solution='part a solution'), Part(text='part b', worked_solution='Solution for b'), Part(text='part c', worked_solution='We now have a solution for c!')], images=[], _main_text='')
property main_text: str#

Main top-level question text.