2.2. Fill in the Blank¶
Another type of question allows you as the instructor to ask for a value. You can test for the value using regular expressions. Leading and trailing whitespace in an answer will automatically be ignored. For example:
.. fillintheblank:: fill1512
:prim_comp: GENERAL
How many bowling pins are used when bowling?
You can put spaces before or after the number without affecting
the correctness of the answer.
You can provide the answer in decimal (10), hexadecimal (0xA),
binary (0b1010), or using scientific notation (1e1).
- :10: Correct.
:0x10: Incorrect. (Note that solutions can be provided in any base
as well).
:.*: Incorrect. Note that the last option given, regardless of
its content, matches any response not already matched by
the previous feedback options. For example, ``:x:`` would
work in the same way.
<exercise label="fillin-integer">
<title>Fill-In, Integer Answer</title>
<statement>
<p>The game of bowling uses <var/> pins that you try to knock down.</p>
</statement>
<setup>
<var>
<condition number="10">
<feedback>
<p>Arranged in a triangle, there are <m>1+2+3+4 = 10</m> pins, a so-called <term>triangular</term> number.</p>
</feedback>
</condition>
<condition number="16">
<feedback>
<p><em>Close</em>! You may have used hexadecimal notation, when you did not really mean to.</p>
</feedback>
</condition>
<condition string=".*">
<feedback>
<p>Incorrect.</p>
</feedback>
</condition>
</var>
</setup>
</exercise>
You can have multiple blank areas to fill in.
.. fillintheblank:: fillDecVar1 Fill in the following: |blank| ``age =`` |blank| ``;`` to declare ``age`` to be an integer and set its value to 5. - :int: Correct. You typically use whole numbers for ages after age 1. :.*: Remember that Java uses just the first three letters of the word integer to define an integral type. - :5: Correct. You can initialize to a value. :.*: Use ``5`` in the second blank.
Case-insensitive answers are supported:
.. fillintheblank:: fitb_casei
:casei:
What is the opposite of yes?
- :no: Correct.
:.*: The correct answer is no, No, nO, or NO.
Numeric answers may provide a tolerance, to accept a range of correct answers.
.. fillintheblank:: fitb_tolerance
What is 1/3 as a decimal value? Provide at least three `significant
figures <https://en.wikipedia.org/wiki/Significant_figures>`_.
- :0.333 0.0005: Correct. Any value in the range of 0.333±0.0005 is
correct.
:.*: Incorrect. Did you provide three `significant
figures`_?
You have attempted of activities on this page