MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Redirecting input

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92419] Re: Redirecting input
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Tue, 30 Sep 2008 21:49:25 -0400 (EDT)
  • References: <gbl2vp$m00$1@smc.vnet.net> <gbnph9$psa$1@smc.vnet.net> <gbqct3$e91$1@smc.vnet.net>

Ignacio Plazeta wrote:
>> This is one of those questions where I feel it would be helpful to know 
>> more about what you are doing. 
> 
> Dear Friends
> 
> I'm developing a package for math exams.
> You are asked, by example, :
> "What's the derivative of Sin[x] ?"
> and answering
> 
> "Cos[x] Enter"
> 
> is nicer than
> 
> "myAnswer[ Cos[x] ] Enter".
> 
> Many thanks for your replies.
> 
> Ignacio Plazeta
> 
> 
Set up a data structure containing your entire exam:

exam = {{"2+2", 4}, {"Derivative of Sin[x]",
    Cos[x]}, {"Derivative of Cos[x]", -Sin[x]}};

Now define a function that asks a question:

ask[pair_] := Module[{answer},
   answer = Input[pair[[1]]];
   If[answer == pair[[2]], correctAnswers++;]
   ];

Finally, apply this function to each question-answer pair in turn:

correctAnswers = 0;
Map[ask, exam];
MessageDialog[StringForm["`` correct answers", correctAnswers]]

Note that this is a very simple setup - you could elaborate it in all 
sorts of ways - such as creating a single GUI window to perform the 
whole exam - but this is a reasonable starting point. One important 
point is that the definition of the questions has been totally separated 
from the code that asks the questions.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Plotting f = Function[x,expr] and f[x_] := expr
  • Next by Date: Re: Variations on ShadowPlot3D
  • Previous by thread: Re: Redirecting input
  • Next by thread: Manipulate / Space Phasor