%try: % eval(f'from {__name__} import *') %except: % pass %end %def chok(ok): % if ok: #✔ \\ % else: #✘ \\ % end %end %def chq( % idx=None #either not there or a (list of) number or the same as ``htmlbr`` % ,htmlbr='
' # html delimiter if no idx =/ more idx % # #the following can also be defined in either __init__.py or in the language html % ,**ka % # ,chames # input names (per idx a html/tex string, e.g. r"\(\alpha\)") % # ,champles # input examples ( " ) % # ,chadios # texts for radio buttons (a tuple per idx) % # ,checkos # texts for check boxes (a tuble per idx) % # ,chow # a function to show the result (e.g. util.tx) % ): % if idx is None: % idxs = range(len(results)) % else: % try: % idxs = [int(i) for i in idx] % except: % try: % idxs = [int(idx)] % except: % idxs = range(len(results)) % htmlbr = idx % end % end % end % more_idx = len(idxs) > 1 % def _getidx(n,i): % if n in ka: % nv = ka.get(n,'') % else: % nv = env.get(n,'') % end % try: % if isinstance(nv,list) or isinstance(nv,dict): % return nv[i] % elif not more_idx: # use tuple for chadios and checkos % return nv % end % except: % return '' % end % end % for idx in idxs: % if more_idx: {{! htmlbr}} % end % chame = _getidx('chames',idx) {{! chame}} % chample = _getidx('champles',idx) % choice = _getidx('chadios',idx) % checks = _getidx('checkos',idx) % chowfun = _getidx('chow',idx) % if choice: % for i,val in enumerate(choice): % answ = str(i+1) % # mention answ in val to link to saved value of answer (1. 2. ) % # have a
at the end of ``val`` for vertical alignment % end % elif checks: % for i,val in enumerate(checks): % answ = chr(65+i) % end % else: % if not answered: {{! chample}} % if points[idx] > 0: [{{points[idx]}}P]\\ % end % else: % if chowfun: {{!chowfun(results[idx])}}\\ % else: {{!results[idx]}}\\ % end % end % end % if answered: % if answers[idx].strip() != '': ({{answers[idx]}} \\ % chok(bool(oks[idx])) ) % end % if oks[idx]: [{{points[idx]}}P] % else: [0P] % end % end % end %end %def chinc(lnk, nr):
% include(lnk,withnr=str(nr))
%end %if defined('withnr') and withnr: % nm = __name__.replace('chcko.','') % if '.' in nm:
{{withnr}} {{nm}} % if points: {{sum(points)}}P % end
%end %end