Problem with Adaptive Hint XML#
Template#
<problem>
<text>
<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 'incorrect answer 1' in ans:
hint = 'hint for incorrect answer 1'
elif 'incorrect answer 2' in ans:
hint = 'hint for incorrect answer 2'
if hint:
hint = "<font color='blue'>Hint: {0}</font>".format(hint)
new_cmap.set_hint_and_mode(aid,hint,'always')
</script>
<p>TEXT OF PROBLEM</p>
<p>
<customresponse cfn="test_str" expect="ANSWER">
<textline correct_answer="answer" label="LABEL TEXT"/>
<hintgroup hintfn="hint_fn"/>
</customresponse>
</p>
</text>
</problem>
Note
If the hints that you supply include characters, the letters must be lowercase.