zeroo
zeroo

Reputation: 11

How do I generate multiple-choice homework set for rational numbers using Mathematica?

I'm trying to generate a multiple choice question set for rational numbers for the following operations: addition, subtraction, multiplication and division.

Something like

01) the value of 2/3 + 5/4 is: a) b) c) d) e)

02) the value of 2/3 * 5/8 is: a) b) c) d) e)

and so on for about 25 questions. How do I do this using Mathematica?

EDIT

  1. I get an error when I try to run yoda's code and couldn't figure out why. Here's the error message:

  2. Here is a mockup showing the final output that I'd like:

  3. The number generation is good, but would be better if they were in the interval -100 < x < 100 at random.

Upvotes: 0

Views: 1055

Answers (2)

abcd
abcd

Reputation: 42235

My interpretation is the same as that of rcollyer's – you want to randomly generate 25 pairs of rational numbers and with the 4 choices being the result of {+,-,*,/} on each pair, but in a shuffled order. The question is then a single randomly chosen operation on the corresponding pair of fractions.

In order to do that, I strongly suggest reading the answer to Sasha's question on generating uniformly distributed rational numbers with an upper bound on the denominator. Specifically, the function RandomFarey, which is Sasha's implementation of btilly's answer. I suggest this instead of the more intuitive Rationalize[RandomReal[...]] approach, because if you're setting a homework for fractions, it's probably for an elementary/middle school class, and you might not want any arbitrary rational number that the obvious approach might throw up (e.g., {273/391, 193/239}, which probably might be a bit too much, depending on the level).

Now that we have a generating function for the rational numbers, all that needs to be done is generating them up, creating the answer choices, shuffling, and creating a random set of questions and laying them out neatly. Here's one approach of doing that.

makeHomework[n_Integer, denominator_Integer] := 
 Module[{rationalPairs = RandomFarey[denominator, 2 n]~Partition~2, 
   operators = {Plus, Subtract, Times, Divide}, 
   randomOp := RandomChoice[{"+", "-", "\[Times]", "\[Divide]"}], 
   choiceList, questionList},

  choiceList = Outer[Apply, operators, rationalPairs, 1];
  questionList = #1 <> randomOp <> #2 <> "=" & @@@ 
    Map[ToString[# // TraditionalForm] &, rationalPairs, {2}];

  Grid[Transpose@{questionList, 
     Row@MapThread[Labeled, {#, {"(a)", "(b)", "(c)", "(d)"}}] & /@ 
      Transpose@choiceList},
   Spacings -> {0, 1}]
  ]

For example, evaluating makeHomework[5, 10] gives:

enter image description here

This probably takes you 90% of the way there. I'm really in a rush, so there are a few things I have not done, but I hope that you or someone else can address it. They're mostly trivial.

  1. I don't account for integers. These will mess up the layout (that one will be a little off the line), if the generator were to throw one up.
  2. I forgot the serial number
  3. The label sizes should be smaller (or conversely, the numbers should be bigger)
  4. Other frills and prettifications

Upvotes: 3

Nasser
Nasser

Reputation: 13141

Can you just type it in a grid? something like this: (you did not say what your a,b,c,d are supposed to be, if you clarify that, I can update this. I assume you will have some choices to pick from somewhere. This can be easily added.

enter image description here

t1 = "the value of ";
t2 = " is :  a)  b)  c)   d)";
a = {"1/2", "3/4", "8/9", "4/3"};
b = {"5/6", "5/6", "9/5", "7/9"};
choice = {"a) b) c) d)"};
r = Table[{i, t1, a[[i]] + b[[i]], t2}, {i, 1, Length[a]} ];
r = Insert[r, {" mid term exam", SpanFromLeft}, 1];
r = Insert[r, {" no cheating allowed", SpanFromLeft}, -1];
Grid[
 r,
 Frame -> {1 -> True, All}, Spacings -> {.4, 1}, Alignment -> Center
 ]

edit(1)

Here is also a demo using Mathematica to generate algebra quiz questions. May be this can give the OP more ideas:

http://demonstrations.wolfram.com/AlgebraQuiz/

Upvotes: 2

Related Questions