Commits

Christopher De Vries committed 308f616

Updated to lates version.

  • Participants
  • Parent commits a58caad

Comments (0)

Files changed (4)

File sampletest.py

 head = head_template%{'title':'Sample Exam','designation':'A'}
 sys.stdout.write(head)
 
-f = open('testquestions.qb','r')
+f = open('testquestions.tex','r')
 qb = t.parseQuestionBank(f)
 f.close()
+qlist = ['q1','q2','q5']
 
 t.newSection(sys.stdout,"Multiple Choice","Please pick the appropriate answer. Each quesiton is worth 1 point.")
 t.beginEnumeration(sys.stdout)
-for i in ['q1','q2','q5']:
-    sys.stdout.write(qb[i])
+for i in qlist:
+    sys.stdout.write(qb[i][0])
 t.endEnumeration(sys.stdout)
+t.beginAnswers(sys.stdout)
+for i in qlist:
+    sys.stdout.write(qb[i][1])
+t.endAnswers(sys.stdout)
 t.endTest(sys.stdout)
 
     """f is an iterable file in the question bank format."""
     questions = {}
     label = ""
+    question = ""
     content = []
 
     beginblock = re.compile(r'%%b\s+(.+)')
+    answerblock = re.compile(r'%%a')
     endblock = re.compile(r'%%e')
 
     for ln in f:
         if beginmatch:
             label = beginmatch.group(1)
             content = []
+        elif answerblock.match(ln):
+            question = ''.join(content)
+            content = []
         elif endblock.match(ln):
-            questions[label] = ''.join(content)
+            questions[label] = [question,''.join(content)]
         else:
             content.append(ln)
     return questions
     fout.write('\\subsection*{%s}\n'%title)
     fout.write(instructions)
 
+def beginAnswers(fout):
+    fout.write('\\clearpage\n')
+    fout.write('\\subsection*{Answers}\n')
+    fout.write('\\begin{tightenumerate}\n')
+
+def endAnswers(fout):
+    fout.write('\\end{tightenumerate}\n')
+
 def endTest(fout):
     fout.write('\\end{document}\n')
 

File testquestions.qb

-%%b q1
-\item What is your name?
-\begin{multchoice}
-\item Robert
-\item Bob
-\item Steve
-\item all of the above
-\item none of the above
-\end{multchoice}
-%%e
-
-%%b q2
-\item What is your favorite color?
-\begin{multchoice}
-\item Red
-\item Blue
-\item Green
-\item Red\ldots no Blue!
-\item none of the above
-\end{multchoice}
-%%e
-
-%%b q3
-\item What is your quest?
-\begin{multchoice}
-\item To cross this bridge.
-\item To seek the holy grail.
-\item To get more sleep.
-\item all of the above
-\item none of the above
-\end{multchoice}
-%%e
-
-%%b q4
-\item What is the capital of Estonia?
-\begin{multchoice}
-\item Wha?
-\item I don't know.
-\item Where is Estonia?
-\item Tallinn
-\item Chicago
-\end{multchoice}
-%%e
-
-%%b q5
-\item What is the airspeed velocity of an unlaiden swallow?
-\begin{multchoice}
-\item 10 mph
-\item 25 mph
-\item African or European swallow?
-\item In English or Metric units?
-\item In light or heavy winds?
-\end{multchoice}
-%%e
-

File testquestions.tex

+\documentclass[12pt]{article}
+\usepackage{graphics}
+\usepackage{pict2e}
+\usepackage{picins}
+
+\newcounter{saveenumi}
+\newcounter{mchoice}
+\newenvironment{multchoice}{\begin{list}{\Alph{mchoice}.}{\setlength{\topsep}{0ex}
+\setlength{\itemindent}{0em}
+\setlength{\labelwidth}{1em}
+\setlength{\leftmargin}{3em}
+\setlength{\listparindent}{0em}
+\setlength{\itemsep}{0ex}
+\setlength{\parsep}{0ex}
+\usecounter{mchoice}}}{\end{list}}
+\newcommand{\answer}[1]{Answer: #1}
+\newcommand{\question}[1]{\item[#1]}
+
+\setlength{\topmargin}{-0.5in}
+\setlength{\textheight}{9.0in}
+\setlength{\oddsidemargin}{-0.25in}
+\setlength{\evensidemargin}{\oddsidemargin}
+\setlength{\textwidth}{7.0in}
+
+\setlength{\headheight}{0.25in}
+\setlength{\headsep}{0.25in}
+\setlength{\footskip}{0.5in}
+\setlength{\marginparsep}{0.2in}
+\setlength{\marginparwidth}{0.0in}
+
+\setlength{\unitlength}{0.1in}
+\newlength{\myleftmargin}
+\setlength{\myleftmargin}{\leftmargin}
+\newcounter{mycounter}
+\pagestyle{myheadings}
+\markright{Question Bank}
+\newcommand{\ds}{\displaystyle}
+
+\begin{document}
+\sloppy
+\noindent
+\thispagestyle{empty}
+\begin{center}
+{\Large Question Bank} \vspace{0.2in}
+\end{center}
+
+\begin{list}{\arabic{enumi}.}{}
+%%b q1
+\question{q1} What is your name?
+\begin{multchoice}
+\item Robert
+\item Bob
+\item Steve
+\item all of the above
+\item none of the above
+\end{multchoice}
+%%a
+\answer{E}
+%%e
+
+%%b q2
+\question{q2} What is your favorite color?
+\begin{multchoice}
+\item Red
+\item Blue
+\item Green
+\item Red\ldots no Blue!
+\item none of the above
+\end{multchoice}
+%%a
+\answer{B}
+%%e
+
+%%b q3
+\question{q3} What is your quest?
+\begin{multchoice}
+\item To cross this bridge.
+\item To seek the holy grail.
+\item To get more sleep.
+\item all of the above
+\item none of the above
+\end{multchoice}
+%%a
+\answer{B}
+%%e
+
+%%b q4
+\question{q4} What is the capital of Estonia?
+\begin{multchoice}
+\item Wha?
+\item I don't know.
+\item Where is Estonia?
+\item Tallinn
+\item Chicago
+\end{multchoice}
+%%a
+\answer{D}
+%%e
+
+%%b q5
+\question{q5} What is the airspeed velocity of an unlaiden swallow?
+\begin{multchoice}
+\item 10 mph
+\item 25 mph
+\item African or European swallow?
+\item In English or Metric units?
+\item In light or heavy winds?
+\end{multchoice}
+%%a
+\answer{C}
+%%e
+\end{list}
+\end{document}