Skip to navigation

expected_answer

View as MarkdownOpen in Claude

Build an expected_answer dict for a gather question’s expected_answer argument in add_gather_question(). It takes the same arguments, and applies the same checks, as Step.set_expected_answer().

from signalwire.core.contexts import expected_answer

Parameters

digits
int | NoneDefaults to None

The exact number of digits, from 1 to 64. Can’t be combined with min_digits or max_digits.

min_digits
int | NoneDefaults to None

Keyword-only. The fewest digits, from 1 to 64. Requires max_digits.

max_digits
int | NoneDefaults to None

Keyword-only. The most digits, from 1 to 64, and at least min_digits. Requires min_digits.

Returns

dict[str, int] — {"digits": N} or {"min_digits": a, "max_digits": b}.

Raises

ValueError for a count outside 1 to 64, a min_digits greater than max_digits, digits combined with a range, or a range with only one end.

Example

from signalwire.core.contexts import expected_answer
print(expected_answer(5)) # {'digits': 5}
print(expected_answer(min_digits=4, max_digits=6)) # {'min_digits': 4, 'max_digits': 6}