Timing Responses

\Adele had a question about how to time a student's response to a \question.  I thought some others might be interested in this so here is an \excerpt from my response.\>

As you can see, TimeUsed won't measure real time.

?TimeUsed

Date will do it:

?Date

\Here is one way to define a  function will ask for a response to a \question and time the response.  Notice how it is modular in that the \question and the timing functionality are separated.\>

\First, here's a question with a random parameter - It's output is 	he student question parameter followed by the student response.  There are 
o arguments here, but you could have them to control the range of random 
umbers or include some options  These are the kind of definitions that would \be in the package that your students' notebooks would  read.\>

Note to Adele:  I changed RootQuestion a bit from what I sent you so that it has an \optional argument

RootQuestion[ ] will ask for the square root of a random \integer between 1 and 200, while RootQuestion[n] will pick from the integers \between 1 and n.

\RootQuestion[n_:200]:=(k=Random[Integer,{1,n}];      {k,Input["What is the approximate square root of \?"]})\>

RootQuestion could be used separately

RootQuestion[]

The following is needed to be able to time the response

Attributes[TimedResponse]={HoldFirst}

\Timed response takes any question and logs in the starting and \ending times for the question.   The reason the HoldFirst attribute is needed \is that otherwise the question is evaluated as an argument and then, very \quicky, StartTime is recorded, response is set to the question response and 	hen the output with current Date[] is returned, but the pause in answering 	he question is before the StartTIme is recorded.  With HoldFirst, question \isn't evaluated immediately.\>

\TimedResponse[question_]:=     (StartTime=Date[];     response=question;     {response,{StartTime,Date[]}})\>

TimedResponse[RootQuestion[]]

\I'll let you figure out how to get the elapsed time between start \and end times.\>

If you define something like this in your package

\Quiz:={TimedResponse[RootQuestion[]],TimedResponse[\SomeOtherQuestion[]] (* more questions *)}\>

\Then the student's notebook would only contain a cell that read the \package (this could be made almost invisible) and \>

Quiz