Purpose os __student_answer__ in Python3 templates

Purpose os __student_answer__ in Python3 templates

by Antonio Gortan -
Number of replies: 2

What is the purpose of the line:

__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""

in Python3 (and also in Python2, by the way) templates?

I doesn't seem to have any use, since the __student_answer__ variable is not used anywhere in the template.

By debugging the template I've noticed it creates a huge docstring with the student answer contents right after the student answer, but it doesn't seem to have any purpose.

Besides, I've deleted the line in some templates of my Python3 questions and the questions kept working ok as before - so I wonder if Code Runner does some sort of checking I dont't know but that just happens not to affect the particular questions I have.

Also, the template python3_w_input doesn't have it, and it doesn't seem to make any difference.

Anybody knows something on this?


In reply to Antonio Gortan

Re: Purpose os __student_answer__ in Python3 templates

by Richard Lobb -

That line is mostly a fossil from earlier days. I originally used it in the documentation to illustrate that question authors could treat the student answer as a string variable and perform simple extra checks using it. For example, even without customising the question they might write test code like, 

if 'break' in __student_answer__:
    print("Your answer is not allowed to use 'break' statements")
    print(some_student_func(...)) # The normal test

Nowadays such test code usually goes in the template itself, or in the prototype, or in TEST.extra or GLOBAL_EXTRA fields. And in any case such tests are better done by parsing the student answer properly (if a parser is available) rather than with a simple string test.

I left the line in the template thinking it might help authors to realise what could be done, but reading your post I now realise it's probably confusing rather than helping. But ... if I remove it from the existing python3 and python2 prototypes I'll break any questions using it in the originally-intended manner. I wonder if any/many question authors are using it? Comments, anyone?

In reply to Richard Lobb

Re: Purpose os __student_answer__ in Python3 templates

by Antonio Gortan -

Thanks Richard, for your quick answer.

I thought it should have been some leftover code from something else. Anyway, your explanation was helpful because it showed me another way to check student code. It already gave me some ideas...

Thanks a lot.