Validate that the answer is within a range. The answer must be of a type that can be compared to the lower and upper bounds. :return: The answer, if it is within the range; otherwise, None.
(lower, upper)
| 116 | |
| 117 | @staticmethod |
| 118 | def in_range(lower, upper): |
| 119 | """ |
| 120 | Validate that the answer is within a range. The answer must be of a type that can |
| 121 | be compared to the lower and upper bounds. |
| 122 | :return: The answer, if it is within the range; otherwise, None. |
| 123 | """ |
| 124 | |
| 125 | def _validate(answer): |
| 126 | return ( |
| 127 | answer if lower <= answer <= upper else None, |
| 128 | f"{answer} must be between {lower} and {upper}.", |
| 129 | ) |
| 130 | |
| 131 | return _validate |
| 132 | |
| 133 | |
| 134 | # snippet-end:[python.example_code.glue.helper.Question] |
no outgoing calls
no test coverage detected