Skip to content

Instantly share code, notes, and snippets.

@timmc-edx
Last active March 13, 2025 13:38
Show Gist options
  • Save timmc-edx/6c6004c9beb42da316d0dc75138325c5 to your computer and use it in GitHub Desktop.
Save timmc-edx/6c6004c9beb42da316d0dc75138325c5 to your computer and use it in GitHub Desktop.
Loncapa problem allowing straight-up Python execution, returning output
<problem>
<script type="loncapa/python">
out = "[missing]"
def run_code(expect, answer_inputs):
global out
exec(answer_inputs, globals(), globals())
return {
"input_list": [
{
"ok": True,
"msg": f"Output:\n{out}",
"grade_decimal": 1,
},
],
}
</script>
<customresponse cfn="run_code">
<p>Set output variable <code>out</code> to see results.</p>
<textbox>out = "..."</textbox>
</customresponse>
</problem>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment