in2lambda.api.question.QuestionΒΆ
- class in2lambda.api.question.Question(title: str = '', parts: list[~in2lambda.api.part.Part] = <factory>, images: list[str] = <factory>, main_text: str = <property object>, _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 in2lambda.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[~in2lambda.api.part.Part] = <factory>, images: list[str] = <factory>, main_text: str = <property object>, _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 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 in2lambda.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.
- Parameters:
elem β A string or panflute element denoting a worked solution.
Examples
>>> from in2lambda.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.
Setting the attribute multiple times appends to the current value with a newline. This allows question text to be dynamically appended.
Examples
>>> from in2lambda.api.question import Question >>> question = Question() >>> question.main_text = "hello" >>> question.main_text = "there" >>> question.main_text 'hello\nthere'