Problem with """ in a python question

Problem with """ in a python question

von Laurent Berger -
Anzahl Antworten: 2

Hi,

I have got a problem with a question.

This answer is wrong :

and error is

and this one is good :

Only difference this is 5 lines.


Now my template is

prgm_student = """{{ STUDENT_ANSWER }}"""
if 'if' not in prgm_student:
    raise NameError('vous devez utiliser if')
if 'else' not in prgm_student:
    raise NameError('bizarre pas de else')


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

SEPARATOR = "#<ab@17943918#@>#"

{% for TEST in TESTCASES %}
{{ TEST.stdin }}
{{ STUDENT_ANSWER }}
{{ TEST.testcode }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}

 I cannot find where is the problem

Als Antwort auf Laurent Berger

Re: Problem with """ in a python question

von Richard Lobb -
Your template breaks because the student answer ends in a double quote character. The assignment statement on line 1 then finishes with four double-quote characters in a row.

To make it work you need to use the e('py') twig escaper, which puts a backslash in front of all quote characters. The line

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

shows the way.