89 lines
3.2 KiB
YAML
89 lines
3.2 KiB
YAML
---
|
|
metadata:
|
|
display_name: Problem with Adaptive Hint in Latex
|
|
source_code: |
|
|
\subsection{Problem With Adaptive Hint}
|
|
|
|
% Adaptive hints are messages provided to students which depend on
|
|
% student input. These hints are produced using a script embedded
|
|
% within the problem (written in Python).
|
|
%
|
|
% Here is an example. This example uses LaTeX as a high-level
|
|
% soure language for the problem. The problem can also be coded
|
|
% directly in XML.
|
|
|
|
This problem demonstrates a question with hints, based on using the
|
|
{\tt hintfn} method.
|
|
|
|
\begin{edXscript}
|
|
def test_str(expect, ans):
|
|
print(expect, ans)
|
|
ans = ans.strip("'")
|
|
ans = ans.strip('"')
|
|
return expect == ans.lower()
|
|
|
|
def hint_fn(answer_ids, student_answers, new_cmap, old_cmap):
|
|
aid = answer_ids[0]
|
|
ans = str(student_answers[aid]).lower()
|
|
print('hint_fn called, ans=', ans)
|
|
hint = ''
|
|
if 'java' in ans:
|
|
hint = 'that is only good for drinking'
|
|
elif 'perl' in ans:
|
|
hint = 'not that rich'
|
|
elif 'pascal' in ans:
|
|
hint = 'that is a beatnick language'
|
|
elif 'fortran' in ans:
|
|
hint = 'those were the good days'
|
|
elif 'clu' in ans:
|
|
hint = 'you must be invariant'
|
|
if hint:
|
|
hint = "<font color='blue'>Hint: {0}</font>".format(hint)
|
|
new_cmap.set_hint_and_mode(aid,hint,'always')
|
|
\end{edXscript}
|
|
|
|
What is the best programming language that exists today? You may
|
|
enter your answer in upper or lower case, with or without quotes.
|
|
|
|
\edXabox{type="custom" cfn='test_str' expect='python' hintfn='hint_fn'}
|
|
markdown: !!null
|
|
data: |
|
|
<problem>
|
|
<text>
|
|
<p><h4>Problem With Adaptive Hint</h4></p>
|
|
<p>This problem demonstrates a question with hints, based on using the <tt class="tt">hintfn</tt> method.</p>
|
|
|
|
<customresponse cfn="test_str" expect="python">
|
|
<script type="text/python" system_path="python_lib">
|
|
def test_str(expect, ans):
|
|
print(expect, ans)
|
|
ans = ans.strip("'")
|
|
ans = ans.strip('"')
|
|
return expect == ans.lower()
|
|
|
|
def hint_fn(answer_ids, student_answers, new_cmap, old_cmap):
|
|
aid = answer_ids[0]
|
|
ans = str(student_answers[aid]).lower()
|
|
print('hint_fn called, ans=', ans)
|
|
hint = ''
|
|
if 'java' in ans:
|
|
hint = 'that is only good for drinking'
|
|
elif 'perl' in ans:
|
|
hint = 'not that rich'
|
|
elif 'pascal' in ans:
|
|
hint = 'that is a beatnick language'
|
|
elif 'fortran' in ans:
|
|
hint = 'those were the good days'
|
|
elif 'clu' in ans:
|
|
hint = 'you must be invariant'
|
|
if hint:
|
|
hint = "<font color='blue'>Hint: {0}</font>".format(hint)
|
|
new_cmap.set_hint_and_mode(aid,hint,'always')
|
|
</script>
|
|
<p>What is the best programming language that exists today? You may enter your answer in upper or lower case, with or without quotes.</p>
|
|
<textline correct_answer="python"/>
|
|
<hintgroup hintfn="hint_fn"/>
|
|
</customresponse>
|
|
</text>
|
|
</problem>
|