Students provide input, code-base is hidden

Students provide input, code-base is hidden

de Oli Howson -
Número de respuestas: 2

First, I'm new to this!

I'm trying to write a question wherein students declare a list of test data, ie:

data = [5,4,3,2,1]

This is then run against three python functions A(), B() and C() (which we want to hide from students) and gives them run-time for each.

The algorithms, the timing, etc are not a problem. What I can't figure out is how to write this as a question to be put into moodle. marking as such isn't needed, the students will be forming conclusions from the results and writing that up externally. 

Any pointers how to get started?

En respuesta a Oli Howson

Re: Students provide input, code-base is hidden

de Richard Lobb -

Assuming this is a one-off question, the easiest approach would be to create a standard Python question and customise it with a template along the following lines:

def A(data): ...
def B(data): ...
def C(data): ...

{{ STUDENT_ANSWER }}

A(data)
B(data)
C(data)

However, that isn't very robust against students entering syntactically incorrect code or not defining a variable data. A slightly better approach would do some prechecking of what the student submitted, e.g.

student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
... code to check the string student_answer, issuing error
... messages if not.

def A(data): ...
def B(data): ...
def C(data): ...

exec(student_answer)

A(data)
B(data)
C(data)

Even safer would be to require the student to supply the list as an expression, rather than defining a specific variable. Then you can do

data = eval(student_answer)

instead.

Although you don't want marking, I think it would be discouraging for students to have their answer marked wrong regardless, so you could switch from the usual exact match grader to a regular expression grader, accepting ".*". Then any submission would be marked right.

En respuesta a Richard Lobb

Re: Students provide input, code-base is hidden

de Oli Howson -
Thanks very much. With lots of trial and error I have used this to get what I want. I've not gone the second step so students have to enter d=['some','data'] but that's a problem for another day. As my first ever coderunner question I'm happy I got this far!