| 1 |
% !TeX encoding = UTF-8 |
| 2 |
% !TeX spellcheck = en_US |
| 3 |
% !TEX TS-program = lualatex |
| 4 |
\documentclass{article} |
| 5 |
\usepackage[nostamp]{moodle} |
| 6 |
\ifPDFTeX % FOR LATEX and PDFLATEX |
| 7 |
\usepackage[utf8]{inputenc} % necessary |
| 8 |
\usepackage[T1]{fontenc} % necessary |
| 9 |
\else % assuming XELATEX or LUALATEX |
| 10 |
\usepackage{fontspec} |
| 11 |
\fi |
| 12 |
\usepackage{hyperref} |
| 13 |
\usepackage{python} |
| 14 |
\begin{document} |
| 15 |
|
| 16 |
\section*{Introduction} |
| 17 |
|
| 18 |
This document is intended to check the possibility of generating |
| 19 |
pseudo-calculated questions with the help of Python scripts. |
| 20 |
|
| 21 |
Inspired by |
| 22 |
\url{https://github.com/avohns/python-latex-moodle-quiz/blob/master/simple-examples-eng/example1_arithmetic.tex} |
| 23 |
|
| 24 |
\begin{quiz}[tags={calculated}]{Example Quiz} |
| 25 |
% the following syntax is Python 3 |
| 26 |
% on Ubuntu 20.10, I had to force python to default to python 3 |
| 27 |
% https://stackoverflow.com/a/50331137 |
| 28 |
\begin{python} |
| 29 |
def clozenum_print(pair,op,result): |
| 30 |
print(rf"""\begin{{numerical}} |
| 31 |
${pair[0]} {op} {pair[1]} =$\item {result} |
| 32 |
\end{{numerical}}""") |
| 33 |
def cloze_print(pair,points): |
| 34 |
print(rf"""\begin{{cloze}}[points={points}]{{Arithmetic Quiz |
| 35 |
{(pair[0],pair[1])}}}Solve the following tasks!\\""") |
| 36 |
clozenum_print([x,y],"+",x+y) |
| 37 |
clozenum_print([x,y],"-",x-y) |
| 38 |
clozenum_print([x,y],"*",x*y) |
| 39 |
if pair[0]/pair[1] == pair[0]//pair[1]: |
| 40 |
clozenum_print([x,y],":",x//y) |
| 41 |
print("\end{cloze}") |
| 42 |
for x in range(2,5): |
| 43 |
for y in range(2,5): |
| 44 |
if x > y: |
| 45 |
if x/y == x//y: |
| 46 |
points=1 |
| 47 |
else: |
| 48 |
points=2 |
| 49 |
cloze_print([x,y],points) |
| 50 |
\end{python} |
| 51 |
\end{quiz} |
| 52 |
\end{document} |