How to seed some random numbers in python_w_input questions

Re: How to seed some random numbers in python_w_input questions

by Michael Fairbank -
Number of replies: 0
Thank you Mike. That works. A key thing I had to do was to put some code in TEST.extra, so under "Extra template data", for test case 1, I now have "random.seed(1)", and for test case 2, I now have "random.seed(2)", etc.

Then I modified the template like you showed and I move the {{ TEST.extra }} and {{ STUDENT_ANSWER }} into the main loop. So the template now looks like this:

__saved_input__ = input
def input(prompt=''):
s = __saved_input__(prompt)
print(s)
return s

import random

SEPARATOR = "##"

{% for TEST in TESTCASES %}
# Add any precode for tests as needed
{{ TEST.extra }}
{{ STUDENT_ANSWER }}
{{ TEST.testcode }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}


Thank you for your help.