This “check” is only valid when defining a parameterless function

This “check” is only valid when defining a parameterless function

de Michael Wang -
Número de respuestas: 2

Dear Richard,

It seems that “check” works only when defining a parameterless function:



The running output is empty



But this one works:



I can have the running output in this case


En respuesta a Michael Wang

Re: This “check” is only valid when defining a parameterless function

de Richard Lobb -

Hi Michael

The test program consists of the student answer plus all the various tests. The code you enter into the 'test code' field of each test case is generally expected to result in some output, which can then be checked against the expected output. When executed within a program, a function call is just an expression, which doesn't result in any output unless the function itself generates output. This is different from the behaviour when entered into the Python shell.

So a suitable test for your plus_f function might be 

result = plus_f(17, -3)
print(result)

or just

print(plus_f(13, -3))

and the expected output is of course 14.

Note that the result table does not display any columns that are empty on all test cases, which is why you were not seeing any Got column.

You can if you want make your own question type in which the testcode is just a call to the function; the template code could wrap that in a print function call. But this is more restrictive (the test case is then constrained to being just an expression rather than a sequence of statements) and is likely to add to the confusion of the different behaviour of a function call in the shell context and in a program context.

-- Richard