Python Random Module Questions

Re: Python Random Module Questions

de către Richard Lobb-
Număr de răspunsuri: 1

You could put a statement that sets the seed in the Extra template data field of each test case (a different seed each time). Then, use a per-test template (i.e. by unchecking the Is combinator checkbox) like

{{ TEST.extra}}
{{ STUDENT_ANSWER }}

This has the slight downside that any errors in the students code will have out-by-one line numbers, but students usually seem to get by. [It's possible to correct line numbers by post-processing but that's way harder.]

Ca răspuns la Richard Lobb

Re: Python Random Module Questions

de către Antonio Gortan-

You can also leave the combinator check box checked if necessary, but then you'll have to introduce for loop as:

from random import seed

{% for TEST in TESTCASES %}
{{ TEST.extra }}
{% endfor %}

{{ STUDENT_ANSWER }}

This has worked for me.