Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 16799
Kernel: SageMath 9.1

MasterIt Tutorial

Use this notebook to quickly write your first randomized exercise.

You can refer to the original example as needed while editing (in case you delete the example).

First, write a generator

Edit the below Code cell to create a function to generate the random data used in your exercise.

Use [Ctrl]+[Enter] to see sample output used for your exercise.

load("main.sage") def generator(): # define any variables you'll use x,y = var("x y") # use functions like `choice` and `randrange` to make random choices A = choice([-1,1])*randrange(1,10) B = choice([-1,1])*randrange(1,10) C = choice([-1,1])*randrange(1,10) # Ask for slope or y-intercept? version = choice(['slope','yint']) #Randomly use standard form or silly form equations if choice([True,False]): equations = [ (A*x+B*y==C), (B*x-C*y==A), ] # standard form else: equations = [ [y, "\\times", B, "+", x, "\\times", A, "=", C], [y, "\\times", -C, "+", x, "\\times", B, "=", A] ] # silly form -- must construct LaTeX by hand # build the objects you need return { "equations": equations, "slopes": [ -A/B, B/C, ], "yints": [ C/B, -A/C, ], "version": version, } # preview example data in this notebook print(generator())
{'equations': [2*x - 2*y == 3, -2*x - 3*y == 2], 'slopes': [1, -2/3], 'yints': [-3/2, -2/3], 'version': 'yint'}

Now, write a template

Edit the following PreTeXt exercise template to write your exercise's statement and answer.

Randomized data from the generator can be accessed using <xsl:value-of select="name"/>.

Use [Ctrl]+[Enter] to display your randomly generated exercise in a variety of formats, including HTML and LaTeX.

template = r""" <exercise> <statement> <p> Find the <xsl:choose> <xsl:when test="version='slope'"> slopes </xsl:when> <xsl:otherwise> y-intercepts </xsl:otherwise> </xsl:choose> for each of the following equations. </p> <ul> <xsl:for-each select="equations/*"> <li><m><xsl:value-of select="."/></m></li> </xsl:for-each> </ul> </statement> <answer> <ul> <xsl:choose> <xsl:when test="version='slope'"> <xsl:for-each select="slopes/*"> <li><m><xsl:value-of select="."/></m></li> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:for-each select="yints/*"> <li><m><xsl:value-of select="."/></m></li> </xsl:for-each> </xsl:otherwise> </xsl:choose> </ul> </answer> </exercise> """ exercise = Exercise( name="Slopes and Intercepts of Lines", slug="example", generator=generator, template=template ) from IPython.core.display import display, HTML display(HTML(exercise.html())) exercise.preview()

Find the y-intercepts for each of the following equations.

  • y×6+x×5=5 y \times -6 + x \times 5 = 5
  • y×5+x×6=5 y \times -5 + x \times -6 = 5

Answer:

  • 56 -\frac{5}{6}
  • 1 -1
Data dictionary ----------- {'equations': [[y, '\\times', -6, '+', x, '\\times', 5, '=', 5], [y, '\\times', -5, '+', x, '\\times', -6, '=', 5]], 'slopes': [5/6, -6/5], 'yints': [-5/6, -1], 'version': 'yint'} Data XML ----------- <data><equations><item><item> y </item><item>\times</item><item> -6 </item><item>+</item><item> x </item><item>\times</item><item> 5 </item><item>=</item><item> 5 </item></item><item><item> y </item><item>\times</item><item> -5 </item><item>+</item><item> x </item><item>\times</item><item> -6 </item><item>=</item><item> 5 </item></item></equations><slopes><item> \frac{5}{6} </item><item> -\frac{6}{5} </item></slopes><yints><item> -\frac{5}{6} </item><item> -1 </item></yints><version>yint</version></data> HTML source ----------- <div class="exercise"> <div class="exercise-statement"> <p> Find the y-intercepts for each of the following equations. </p> <ul> <li>\( y \times -6 + x \times 5 = 5 \)</li> <li>\( y \times -5 + x \times -6 = 5 \)</li> </ul> </div> <div class="exercise-answer"> <p><b>Answer:</b></p> <ul> <li>\( -\frac{5}{6} \)</li> <li>\( -1 \)</li> </ul> </div> </div> LaTeX source ------------ \begin{exerciseStatement} Find the y-intercepts for each of the following equations. \begin{itemize} \item \( y \times -6 + x \times 5 = 5 \) \item \( y \times -5 + x \times -6 = 5 \) \end{itemize} \end{exerciseStatement} \begin{exerciseAnswer} \begin{itemize} \item \( -\frac{5}{6} \) \item \( -1 \) \end{itemize} \end{exerciseAnswer} QTI source ------------ <item ident="example-8989" title="example | Slopes and Intercepts of Lines | ver. 8989"> <itemmetadata> <qtimetadata> <qtimetadatafield> <fieldlabel>question_type</fieldlabel> <fieldentry>essay_question</fieldentry> </qtimetadatafield> </qtimetadata> </itemmetadata> <presentation> <material> <mattextxml> <div class="exercise-statement"> <p> <strong>example.</strong> </p> <p> Find the y-intercepts for each of the following equations. </p> <ul> <li> <img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?y \times -6 + x \times 5 = 5" alt="y \times -6 + x \times 5 = 5" title="y \times -6 + x \times 5 = 5" data-latex="y \times -6 + x \times 5 = 5"/> </li> <li> <img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?y \times -5 + x \times -6 = 5" alt="y \times -5 + x \times -6 = 5" title="y \times -5 + x \times -6 = 5" data-latex="y \times -5 + x \times -6 = 5"/> </li> </ul> </div> </mattextxml> <mattext texttype="text/html">&lt;div class="exercise-statement"&gt; &lt;p&gt; &lt;strong&gt;example.&lt;/strong&gt; &lt;/p&gt; &lt;p&gt; Find the y-intercepts for each of the following equations. &lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?y%20%5Ctimes%20-6%20+%20x%20%5Ctimes%205%20=%205" alt="y \times -6 + x \times 5 = 5" title="y \times -6 + x \times 5 = 5" data-latex="y \times -6 + x \times 5 = 5"&gt; &lt;/li&gt; &lt;li&gt; &lt;img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?y%20%5Ctimes%20-5%20+%20x%20%5Ctimes%20-6%20=%205" alt="y \times -5 + x \times -6 = 5" title="y \times -5 + x \times -6 = 5" data-latex="y \times -5 + x \times -6 = 5"&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </mattext> </material> <response_str ident="response1" rcardinality="Single"> <render_fib> <response_label ident="answer1" rshuffle="No"/> </render_fib> </response_str> </presentation> <itemfeedback ident="general_fb"> <flow_mat> <material> <mattextxml> <div class="exercise-answer"> <h4>Partial Answer:</h4> <ul> <li> <img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?-\frac{5}{6}" alt="-\frac{5}{6}" title="-\frac{5}{6}" data-latex="-\frac{5}{6}"/> </li> <li> <img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?-1" alt="-1" title="-1" data-latex="-1"/> </li> </ul> </div> </mattextxml> <mattext texttype="text/html">&lt;div class="exercise-answer"&gt; &lt;h4&gt;Partial Answer:&lt;/h4&gt; &lt;ul&gt; &lt;li&gt; &lt;img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?-%5Cfrac%7B5%7D%7B6%7D" alt="-\frac{5}{6}" title="-\frac{5}{6}" data-latex="-\frac{5}{6}"&gt; &lt;/li&gt; &lt;li&gt; &lt;img style="border:1px #ddd solid;padding:5px;border-radius:5px;" src="https://latex.codecogs.com/svg.latex?-1" alt="-1" title="-1" data-latex="-1"&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </mattext> </material> </flow_mat> </itemfeedback> </item> PreTeXt source ------------ <exercise masterit-seed="8989" masterit-slug="example" masterit-name="Slopes and Intercepts of Lines"><statement><p> Find the y-intercepts for each of the following equations. </p><ul><li><m> y \times -6 + x \times 5 = 5 </m></li><li><m> y \times -5 + x \times -6 = 5 </m></li></ul></statement><answer><ul><li><m> -\frac{5}{6} </m></li><li><m> -1 </m></li></ul></answer></exercise>

Start building your library!

Go to the README to learn how to create a library of exercises that can be exported for use in platforms such as Canvas LMS.