1
$\begingroup$

I wasn't sure what to name this title, I will explain this code just incase some people actually aren't running it on Mathematica..This code will ask you "what is #1 * #2", where #1 and #2 are random integers between 1 and 12 as defined by a and b.. If you get the answer right it says "Great Job" but if you get it wrong it will say "Try again"..

I guess I have 2 questions:

How can I have this repeat multiple times (well use 3 iterations), so the input window would pop ups and ask 3 different multiplication problems...

Assuming we get it wrong, how can I have the same input window ask the same question again until it is answered right?

 Clear[answer,a,b,list];

 a = RandomInteger[{1, 12}];
 b = RandomInteger[{1, 12}];
 list = Input["what is " <> ToString[a] <> " times " <> ToString[b] <> "."];
 If[list == a*b, Print["Great Job"], Print["Try Again"]]
 list

Let me know if I need to clarify anything

$\endgroup$
2
$\begingroup$
Do[SeedRandom[];
 a = RandomInteger[{1, 12}];
 b = RandomInteger[{1, 12}];
 list = Input[
   "what is " <> ToString[a] <> " times " <> ToString[b] <> "?"];
 If[list == a*b, Print["Great Job"], 
  While[list != a b, 
   list = Input[
     "Try again; what is " <> ToString[a] <> " times " <> 
      ToString[b] <> "?"]
   ]
  ]
 , 3]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.