0
$\begingroup$

I have been trying for a long time to generate a question test where operations with 2 rationals appear printed. Can someone help me with the code? shows the following errors. a) The options appear repeated in some questions b) The generation of random numbers for the operations seems to stick. c) The options should present the final result of the operation and not a series of operations where it is indicated what must be done. d) The correct answers should come out at the end after all the questions come out. e) You lack a title and write the questions in bold.

SetAttributes[shuffle, Orderless];

 op = {Plus, Subtract, Times, Divide};

 r1 = RandomChoice[Range[-5, 5]]/RandomChoice[Range[1, 5]];
 r2 = RandomChoice[Range[-5, 5]]/RandomChoice[Range[1, 5]];

 Do[op1 = RandomChoice[op];
 ans = Simplify[r1 op1 r2];
 choices = {ans, 
 ans + RandomChoice[Range[-5, 5]]/RandomChoice[Range[1, 5]], 
 ans + RandomChoice[Range[-5, 5]]/RandomChoice[Range[1, 5]], 
 ans + RandomChoice[Range[-5, 5]]/RandomChoice[Range[1, 5]], 
 ans + RandomChoice[Range[-5, 5]]/RandomChoice[Range[1, 5]]};
 correct = Position[choices, ans][[1, 1]];
 shuffledChoices = RandomSample[choices];
 Print["Pregunta ", i, ":"];
 Print[r1, " ", 
 Which[op1 === Plus, "+", op1 === Subtract, "-", op1 === Times, "*", 
op1 === Divide, ":"], " ", r2, " = ?"];
Print["a) ", shuffledChoices[[1]]];
Print["b) ", shuffledChoices[[2]]];
Print["c) ", shuffledChoices[[3]]];
Print["d) ", shuffledChoices[[4]]];
Print["e) ", shuffledChoices[[5]]];
Print["Respuesta correcta: ", CharacterRange["a", "e"][[correct]]];
Print[""];
If[i == 10, Print["END  test"]], {i, 1, 10}]   
$\endgroup$
2
  • $\begingroup$ Relevant: 76478 and 8875397 from SO. $\endgroup$
    – Syed
    Commented Mar 2, 2023 at 3:43
  • $\begingroup$ I already saw that before asking and it doesn't work for me, what I'm asking for is something else, which is expressed in the description of the question. Thank you $\endgroup$
    – Pamela
    Commented Mar 3, 2023 at 20:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.