Wednesday, November 30, 2016

Sample code for Moodle Quiz questions that have source code samples in them. In Moodle XML format.

<?xml version="1.0" ?>
<quiz>

<!-- "Test" is the quiz question bank name -->
<question type="category">
    <category>
        <text>$course$/Test</text>
    </category>
</question>

<!-- Sample short answer question with a code sample.
See: https://docs.moodle.org/31/en/Moodle_XML_format for more details.
-->
<question type="shortanswer">
    <name>
        <text>Test question</text>
    </name>
     <questiontext format="html">
         <text>Look at the following code:
<![CDATA[
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<pre><code class="python"># Code Sample
def test_function():
   print("Hi")

test_function()
</code></pre>
]]>
What does the program print when it runs?
         </text>
    </questiontext>

    <!-- Case sensitive flag -->
    <usecase>1</usecase>

    <answer fraction="100">
        <text>Hi</text>
        <feedback><text>Correct!</text></feedback>
    </answer>
    <answer fraction="0">
        <text>hi</text>
        <feedback><text>Sorry, but case matters!</text></feedback>
    </answer>
</question>

</quiz>