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