Test for Creation & Use of Variable

Re: Test for Creation & Use of Variable

por Richard Lobb -
Número de respuestas: 0

Assuming you're using some sort of C++-via-Python question type, you have the student's code available in a Python variable, after a statement of the form

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

You can then edit that string in any way you choose before writing it to a file and compiling and running it. For example you could use a regular expressions like "blueLED *= *(\d+)". You should first check that there is exactly one match, then use (say) re.sub() to replace the digit string with a per-test-case number extracted from the test case, e.g. like

pin_num = {{ TEST.extra }}

However, this is all quite a lot of work for one question. It would be much easier to tell the student that they must use a globally-defined variable blueLED (which of course they then shouldn't define themselves). You could define that global variable differently in each test.