libLIST=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libLIST.m"]<>"\n";
libNAMES=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libNAMES.m"]<>"\n";
libIO=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libIO.m"]<>"\n";
libERR=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libERR.m"]<>"\n";
libGUI=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libGUI.m"]<>"\n";
libML=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libML.m"]<>"\n";
libMISC=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libMISC.m"]<>"\n";
libGraphics=ReadString["C:/mathematica/Work/lossofgenerality/MET-CS/HomeWorks/libGraphics.m"]<>"\n";

(*libLIST=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libLIST.m"]<>"\n";
libNAMES=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libNAMES.m"]<>"\n";
libIO=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libIO.m"]<>"\n";
libERR=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libERR.m"]<>"\n";
libGUI=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libGUI.m"]<>"\n";
libML=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libML.m"]<>"\n";
libMISC=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libMISC.m"]<>"\n";
libGraphics=ReadString["/Users/darashayda1xfer/Desktop/MODULES/BU/libs/libGraphics.m"]<>"\n";*)

data1="\n"<>"textfghjkl:="<>ToString[<|

"0"->{"Column[{ToString[\"fghjkl. Decide which of the following are propositions and give the truth value:\",TraditionalForm]"<>","<>"ToString[\"(Yes, No, True, False...) \"]"<>"}]","Column[{ToString[\"fghjkl. Answer with Y or N for yes and no:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},



"1"-><|
"1.1"->{"Column[{ToString[\" #a is an even integer:\"]"<>"}]",
"Column[{ToString[\" #a is divisible by 2:\"]"<>"}]"},

"1.2"->{"Column[{ToString[\" #a ≡ 0 (mod #b):\",TraditionalForm]"<>"}]",
"Column[{ToString[\" #a is divisible by #b\"]"<>"}]"},

"1.3"->{"Column[{ToString[\" #a ≡ #b (mod #c):\"]"<>"}]",
"Column[{ToString[\" #a - #b is divisible by #c:\"]"<>"}]"}
|>,

"2"-><|
(* 2.1 is always False*)
"2.1"->{"Column[{ToString[\" All triangles have 4 sides or more\"]"<>"}]",
"Column[{ToString[\" Any three line segments forms a triangle\"]"<>"}]",
"Column[{ToString[\" Any three line segments enclosing an area is a triangle\"]"<>"}]",
"Column[{ToString[\" Three line segments connecting any 3 points is a triangle\"]"<>"}]",
"Column[{ToString[\" Any three points could form a triangle\"]"<>"}]",
"Column[{ToString[\" Any 3 points form a plane\"]"<>"}]",
"Column[{ToString[\" Any 2 points determine a line\"]"<>"}]",
"Column[{ToString[\" Any two cirlces intersect at two points or no points\"]"<>"}]",
"Column[{ToString[\" Any 3 points determine a cirlce\"]"<>"}]",
"Column[{ToString[\" Any 3 non-intersecting lines are parallel\"]"<>"}]"},

(*2.2 is always True *)
"2.2"->{"Column[{ToString[\" 3 line segments connecting 3 planar points is a tringle\"]"<>"}]",
"Column[{ToString[\" Three line segments connecting any 3 points not on a line is a triangle\"]"<>"}]",
"Column[{ToString[\" Any 3 non-planar points could form a triangle\"]"<>"}]",
"Column[{ToString[\" Any 2 different points determine a line\"]"<>"}]",
"Column[{ToString[\" Any two cirlces intersect at two or one or no points or all points\"]"<>"}]",
"Column[{ToString[\" Any 3 non-planar points determine a circle\"]"<>"}]"}

|>


|>,InputForm]<>";\n ";



data2="listfghjkl:="<>


ToString[{"",""


},InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];

canvas1="\n"<>ToString[Hold[canvasFunc1[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars["text"];
Column[{

ToExpression@text[[1]],
Row[{Row[{Column[{options[[1]]<>")"}],ToExpression@text[[2]]}],Pane[answers[[1]],BaselinePosition->Scaled[0.2]]}] ,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Row[{Row[{Column[{options[[2]]<>")"}],ToExpression@text[[3]]}],Pane[answers[[2]],BaselinePosition->Scaled[0.2]]}] 


}]


]],InputForm]<>"\n ";




variation1=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,p,x,a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,question,list12,teste},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]];

Which[key=="1.1", 
aa=ToString@RandomInteger[{20,100}];
vars={aa};
sol=If[EvenQ[ToExpression@aa]==True, {"Y","y","yes","Yes","True","T","true","t"},{"N","n","No","no","false","False","F","f"}];
parta={StringReplace[text, { "#a"->aa}],vars,sol} ;,

key=="1.2",
aa=ToString@RandomInteger[{15,100}];
bb=ToString@RandomInteger[{3,10}];
sol=If[Mod[ToExpression@aa,ToExpression@bb]==0, {"Y","y","yes","Yes","True","T","true","t"},{"N","n","No","no","false","False","F","f"}];
vars={aa,bb};

parta={StringReplace[text, { "#a"->aa,"#b"->bb}],vars,sol} ;,

key=="1.3",
aa=ToString@RandomInteger[{15,100}];
bb=ToString@RandomInteger[{15,100}];
cc=ToString@RandomInteger[{3,10}];
sol=If[Mod[ToExpression@aa,ToExpression@bb,ToExpression@cc]==0, {"Y","y","yes","Yes","True","T","true","t"},{"N","n","No","no","false","False","F","f"}];
vars={aa,bb,cc};

parta={StringReplace[text, { "#a"->aa,"#b"->bb,"#c"->cc}],vars,sol} ;];

key=RandomChoice[Keys[textfghjkl["2"]]];
text=RandomChoice[textfghjkl["2"][key]];

Which[key=="2.1", 
vars={};
sol={"N","n","No","no","false","False","F","f"};
partb={text,vars,sol} ;,

key=="2.2", 
vars={};
sol={"Y","y","yes","Yes","True","T","true","t"};
partb={text,vars,sol} ;];


vars=ToString[<|"text"->{question, parta[[1]],partb[[1]]},"vars"->{ parta[[2]],partb[[2]]}, "sol"->{ parta[[3]],partb[[3]]}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]]}, { parta[[3]],partb[[3]]}}


(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution1=data1<>data2<>ToString[Hold[Module[{x, a,b,c,d,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,g,h,pp,teste,bb1,list123,pos1,t11,t12,t21,t22,s1,s2,sum1,sum2,k},





varsa=vars[[1]];
varsb=vars[[2]];



(*{aa,bb,cc,dd,ee,gg,pp}=varsa;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];
*)


body={
{"",""

}, 
{Null ,Null} 
};


Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint1=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},  


body={ 
{""
},
{Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

data1="\n"<>"textfghjkl:="<>ToString[<|

"0"->{"Column[{ToString[\"fghjkl. Negate the following statements:\",TraditionalForm]"<>","<>"ToString[\"\"]"<>"}]","Column[{ToString[\"fghjkl. Choose the negation:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},



"1"-><|
(*AND*)
"1.1"->{"Column[{ToString[\" @a is @b, and @a is @c:\"]"<>"}]"},

"1.2"->{"Column[{ToString[\" @a is not @b, and @a is @c:\"]"<>"}]"},

"1.3"->{"Column[{ToString[\" @a is @b, and @a is not @c:\"]"<>"}]"},

"1.4"->{"Column[{ToString[\" @a is not @b, and @a is not @c:\"]"<>"}]"},

(*OR
If, Then*)
"1.5"->{"Column[{ToString[\" @a is @b, or @a is @c:\"]"<>"}]",
"Column[{ToString[\"if @a is not @b, then @a is @c:\"]"<>"}]"},

"1.6"->{"Column[{ToString[\" @a is not @b, or @a is @c:\"]"<>"}]",
"Column[{ToString[\" if @a is @b, then @a is @c:\"]"<>"}]"},

"1.7"->{"Column[{ToString[\" @a is @b, or @a is not @c:\"]"<>"}]",
"Column[{ToString[\"if @a is not @b, then @a is not @c:\"]"<>"}]"},

"1.8"->{"Column[{ToString[\" @a is not @b, or @a is not @c:\"]"<>"}]",
"Column[{ToString[\"if @a is @b, then @a is not @c:\"]"<>"}]"}

|>,

"2"-><|
(* 2.1 is always False*)
"2.1"->{"Column[{ToString[\" @a is @c if and olny if @b is @c:\"]"<>"}]"},

(*2.2 is always True *)
"2.2"->{"Column[{ToString[\"All people are @c :\"]"<>"}]"},

"2.3"->{"Column[{ToString[\"Some people are @c:\"]"<>"}]"}

|>


|>,InputForm]<>";\n ";


data2="listfghjkl:="<>


ToString[
<|

"1.1"->{{"a Freshman","a Sophomore","a Junior", "a Senior"},{"a male", "a female"},{"a foreigner","a local", "a resident"}},
"1.2"->{{"a Freshman","a Sophomore","a Junior", "a Senior"},{"a male", "a female"},{"a foreigner","a local", "a resident"}},
"1.3"->{{"a Freshman","a Sophomore","a Junior", "a Senior"},{"a male", "a female"},{"a foreigner","a local", "a resident"}},
"1.4"->{{"healthy","ailing","heavy", "skinny","diabetic","asmatic"},{"a male", "a female"},{"young", "old", "middle aged", "married","widowed"}},
"1.5"->{{"healthy","ailing","heavy", "skinny","diabetic","asmatic"},{"a male", "a female"},{"young", "old", "middle aged", "married","widowed"}},"1.6"->{{"healthy","ailing","heavy", "skinny","diabetic","asmatic"},{"a male", "a female"},{"young", "old", "middle aged", "married","widowed"}},
"1.7"->{{"healthy","ailing","heavy", "skinny","diabetic","asmatic"},{"a male", "a female"},{"young", "old", "middle aged", "married","widowed"}},"1.8"->{{"healthy","ailing","heavy", "skinny","diabetic","asmatic"},{"a male", "a female"},{"young", "old", "middle aged", "married","widowed"}},

"2.1"->{{"healthy","ailing","heavy", "skinny","diabetic","asmatic"},{"a male", "a female"},{"young", "old", "middle aged", "married","widowed"}},

"2.2"->{{"married", "divorced","students","healthy"}},
"2.3"->{{"opera singers", "sailors","travelers","healthy"}}


|>,InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



canvas2="\n"<>ToString[Hold[canvasFunc2[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data},

{answers,options}=s;

text=vars["text"];
Column[{

ToExpression@text[[1]],
Row[{Row[{Column[{options[[1]]<>")"}],ToExpression@text[[2]]}],Pane[answers[[1]],BaselinePosition->Scaled[0.2]]}] ,
(*makeTextTable2[ToExpression@(vars[[2]][[1]][[1]]),Take[answers,2],ToExpression@vars[[2]][[1]][[2]]],*)

Spacer@100,
Row[{Row[{Column[{options[[2]]<>")"}],ToExpression@text[[3]]}],Pane[answers[[2]],BaselinePosition->Scaled[0.2]]}] 


}]


]],InputForm]<>"\n ";




variation2=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,p,x,a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,question,list12,teste,choices},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]];

Which[key=="1.1", 
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};

sol=StringReplace["@a is not @b, or @a is not @c:", { "@a"->a,"@b"->b,"@c"->c}];

choices=RandomSample[{"@a is not @b, and @a is not @c:",
"@a is not @b, or @a is @c:",
"@a is not @b, then @a is not @c:",
sol},4];

parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,

key=="1.2",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};

sol=StringReplace["@a is @b, or @a is not @c:", { "@a"->a,"@b"->b,"@c"->c}];

choices=RandomSample[{"@a is a @b, and @a is not a @c:",
"@a is not @b, or @a is not @c:",
"@a is @b, or @a is @c:",
sol},4];

parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,

key=="1.3",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};

sol=StringReplace["@a is not @b, or @a is @c:", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"@a is @b, or @a is @c:",
"@a is @b, and @a is not @c:",
"@a is not @b, or @a is not @c:",
sol},4];

parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,


key=="1.4",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};
sol=StringReplace["@a is @b, or @a is @c:", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"@a is @b, and @a is not @c:",
"@a is @b, and @a is @c:",
"@a is @b, or @a is not @c:",
sol},4];

parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,


key=="1.5",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};

sol=StringReplace["@a is not @b, and @a is not @c:", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"@a is not @b, or @a is not @c:",
"if @a is @b, then @a is not @c:",
"@a is @b, and @a is not @c:",
sol},4];

parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,


key=="1.6",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};
sol=StringReplace["@a is @b, and @a is not @c:", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"if @a is not @b, then @a is not @c:",
"@a is not @b, and @a is @c:",
"@a is @b, or @a is not @c:",
sol},4];
parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,


key=="1.7",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};
sol=StringReplace["@a is not @b, and @a is @c:", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"if @a is @b, then @a is @c:",
"@a is not @b, and @a is not @c:",
"@a is @b, or @a is not @c:",
sol},4];
parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,

key=="1.8",
{a}=RandomSample[qNamesList[[All,1]],1];
{b,c}=RandomChoice/@(RandomSample[listfghjkl[key],2]);
vars={a,b,c};
sol=StringReplace["@a is @b, and @a is @c:", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"if @a is not @b, then @a is @c:",
"@a is not @b, and @a is not @c:",
"@a is @b, or @a is not @c:",
sol},4];
parta={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;


];

key=RandomChoice[Keys[textfghjkl["2"]]];
text=RandomChoice[textfghjkl["2"][key]];


Which[key=="2.1", 
ToExpression@(RandomSample@{
ToString[{a,b}=RandomSample[qNamesList[[All,1]],2];
c=RandomChoice@RandomChoice@listfghjkl[key];
vars={a,b,c};
sol=StringReplace["(@a is @c and @b is not @c) or (@b is @c and @a is not @c):", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"(@a is @c and @b is not @c) and (@b is @c and @a is not @c)",
"(@a is @c or @b is not @c) or (@b is @c or @a is not @c)",
"(@a is @c and @b is @c) or (@b is @c and @a is @c)",
sol},4];
partb={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,InputForm]

}),


(*{a,b}=RandomSample[qNamesList[[All,1]],2];
c=RandomChoice@RandomChoice@listfghjkl[key];
vars={a,b,c};
sol="@a and @b are not both @c:";
choices={"hi","bye"};
partb={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,choices} ;,*)


key=="2.2",

ToExpression@(RandomSample@{ 
ToString[{a,b}=RandomSample[qNamesList[[All,1]],2];
c=RandomChoice@RandomChoice@listfghjkl[key];
vars={a,b,c};
sol=StringReplace["Some people are not @c", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"Some people are @c",
"No people are @c",
"All people are not @c",
sol},4];
partb={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,InputForm]
}),


key=="2.3",

ToExpression@(RandomSample@{ 
ToString[{a,b}=RandomSample[qNamesList[[All,1]],2];
c=RandomChoice@RandomChoice@listfghjkl[key];
vars={a,b,c};
sol=StringReplace["No people are @c", { "@a"->a,"@b"->b,"@c"->c}];
choices=RandomSample[{"Some people are not @c",
"No people are not @c",
"All people are @c",
sol},4];
partb={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices} ;,InputForm]
})
(*{a,b}=RandomSample[qNamesList[[All,1]],2];
c=RandomChoice@RandomChoice@listfghjkl[key];
vars={a,b,c};
sol="@a will not @b and @c will not @b";
choices={"hi","bye"};
partb={StringReplace[text, { "@a"->a,"@b"->b,"@c"->c}],vars,sol,choices}; *)

];
vars=ToString[<|"text"->{question, parta[[1]],partb[[1]]},"vars"->{ parta[[2]],partb[[2]]}, "sol"->{ parta[[3]],partb[[3]]},"choices"->{ parta[[4]],partb[[4]]}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]]}, { parta[[3]],partb[[3]]},{ parta[[4]],partb[[4]]}}


(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution2=data1<>data2<>ToString[Hold[Module[{x, a,b,c,d,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,g,h,pp,teste,bb1,list123,pos1,t11,t12,t21,t22,s1,s2,sum1,sum2,k},





varsa=vars[[1]];
varsb=vars[[2]];



(*{aa,bb,cc,dd,ee,gg,pp}=varsa;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];
*)


body={
{"",""

}, 
{Null ,Null} 
};


Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint2=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},  


body={ 
{""
},
{Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

(* OLD data variations and canvas for q#3

data1="\n"<>"textfghjkl:="<>ToString[<|

"0"->{"Column[{ToString[\"fghjkl. Complete the following proof:\",TraditionalForm]"<>","<>"ToString[\"\"]"<>"}]","Column[{ToString[\"fghjkl. Choose appropriate parts of the proof:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},


(* key=1 contains all kinds of proofs and it variates missing parts *)
"1"-><|
"1.1"->{

(* values needs to be double-string*)
<|
"s1"->ToString["Prove by contradiction.\nProposition: If @a,@b ∈ ℤ, then "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2",InputForm],

"s2"->"ToString[\"Proof:\n\n Suppose this propostion is false.\"]",

"s3"->ToString["This conditional statement being false means there exist numbers @a and @b for which @a,@b ∈ ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",InputForm],

"s4"->ToString["Thus there exists integers @a,@b ∈ ℤ for which "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2",InputForm],

"s5"->ToString["From this equation we get "<>ToString["@a"^2, TraditionalForm]<>"=4@b+2=2(2@b+1), so "<>ToString["@a"^2,TraditionalForm]<>" is even.",InputForm],

"s6"->ToString["Since "<>ToString["@a"^2, TraditionalForm]<> " is even, it then follows that @a is even, so @a=2@c, for some integer @c.",InputForm],

"s7"->ToString["Now plug @a=2@c back into the equation  "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2.",InputForm],

"s8"->ToString["We get "<>ToString["(2@c)"^2, TraditionalForm]<>"-4@b=2. so "<>ToString["4"*"@c"^2-"4"*"@b", TraditionalForm]<>"=2. Dividing by 2, we get "<> ToString["2"*"@a"^2, TraditionalForm]<>"-2@b=1",InputForm],

"s9"->ToString["Therefore 1= "<>ToString["2"*("@c"^2-"@b"), TraditionalForm]<>", and since "<>ToString["@c"^2-"@b", TraditionalForm]<>" ∈ ℤ, it follows that 1 is even",InputForm],

"s10"->ToString["Since we know 1 is not even, something went wrong.\nBut all the logic after the first line of proof is correct, so it must be that the first line was incorrect. In other words, we were wrong to assume the proposition was false. Thuse the proposition is true. ■",InputForm]
|>
}

|>




|>,InputForm]<>";\n ";


data2="listfghjkl:="<>


ToString[
<|

"1"->{}


|>,InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



canvas3="\n"<>ToString[Hold[canvasFunc3[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data,locations,assoc},

{answers,options}=s;

text=(vars["text"]);
locations=(vars["keys"]); (*get the locations  to place the answers *)
assoc=ToExpression/@text[[2]]; (* this assignment has to happen of the original value of text[[2]] is preserved, see issues in Association*)
Table[assoc[locations[[i]]]=Pane[answers[[i]],BaselinePosition->Scaled[0.2]], {i,1,Length@locations}];


Column@Values[assoc]





]],InputForm]<>"\n ";




variation3=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,key2,p,x,a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,question,list12,teste,choices},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]]; (* for proofs this text is actually an association again*)

Which[key=="1.1", 
{a,b,c}=nLetters[{"a","z"},3];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This conditional statement being true means there exist numbers @a and @b for which @a,@b∈ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",
"This conditional statement being false means there exist numbers @a and @b for which @a,@b∈ℝ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",
"This conditional statement being true means there exist numbers @a and @b for which @a,@b∉ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2"<>"is false"

},
key2[[i]]=="s4",
{
"Thus there exists integers @a,@b ∈ ℝ for which "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2",
"Thus there exists integers @a,@b ∈ ℤ for which "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2",
"Thus there exists integers no @a,@b ∈ ℤ for which "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"
}
,
key2[[i]]=="s5",
{
"From this equation we get "<>ToString["@a"^2, TraditionalForm]<>"=4@b+2=2(2@b-1), so "<>ToString["@a"^2,TraditionalForm]<>" is even.",
"From this equation we get "<>ToString["@a"^2, TraditionalForm]<>"=4@b+2=2(2@b+1), so "<>ToString["@a"^2,TraditionalForm]<>" is odd.",
"From this equation we get "<>ToString["@a"^2, TraditionalForm]<>"=4@b+4=2(2@b+1), so "<>ToString["@a"^2,TraditionalForm]<>" is even."
},
key2[[i]]=="s6",
{
"Since "<>ToString["@a"^2, TraditionalForm]<> " is odd, it then follows that @a is even, so @a=2@c, for some integer @c.",
"Since "<>ToString["@a"^2, TraditionalForm]<> " is even, it then follows that @a is odd, so @a=2@c, for some integer @c.",
"Since "<>ToString["@a"^2, TraditionalForm]<> " is even, it then follows that @a is even, so @a=4@c, for some integer @c."
},
key2[[i]]=="s7",
{
"Now plug @a=2@c back into the equation  "<>ToString["@a"^2, TraditionalForm]<>"-4@b=4.",
"Now plug @a=2@c back into the equation  "<>ToString["@a"^2, TraditionalForm]<>"+4@b=2.",
"Now plug @a=4@c back into the equation  "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2."

},
key2[[i]]=="s8",
{
"We get "<>ToString["(2@c)"^2, TraditionalForm]<>"-4@b=4. so "<>ToString["4"*"@c"^2-"4"*"@b", TraditionalForm]<>"=2. Dividing by 2, we get "<> ToString["2"*"@a"^2, TraditionalForm]<>"-2@b=1",
"We get "<>ToString["(2@c)"^2, TraditionalForm]<>"-4@b=2. so "<>ToString["4"*"@c"^2+"4"*"@b", TraditionalForm]<>"=2. Dividing by 2, we get "<> ToString["2"*"@a"^2, TraditionalForm]<>"-2@b=1",
"We get "<>ToString["(2@c)"^2, TraditionalForm]<>"-4@b=2. so "<>ToString["4"*"@c"^2-"4"*"@b", TraditionalForm]<>"=4. Dividing by 2, we get "<> ToString["2"*"@a"^2, TraditionalForm]<>"-2@b=1"

},
key2[[i]]=="s9",
{
"Therefore 1= "<>ToString["2"*("@c"^2-"@b"), TraditionalForm]<>", and since "<>ToString["@c"^2+"@b", TraditionalForm]<>" ∈ ℤ, it follows that 1 is even",
"Therefore 1= "<>ToString["2"*("@c"^2-"@b"), TraditionalForm]<>", and since "<>ToString["@c"^2-"@b", TraditionalForm]<>" ∈ ℝ, it follows that 1 is even",
"Therefore 1= "<>ToString["2"*("@c"^2-"@b"), TraditionalForm]<>", and since "<>ToString["@c"^2-"@b", TraditionalForm]<>" ∈ ℤ, it follows that 1 is odd"

},

key2[[i]]=="s10",

{
"Since we know 1 is not odd, something went wrong.\nBut all the logic after the first line of proof is correct, so it must be that the first line was incorrect. In other words, we were wrong to assume the proposition was false. Thuse the proposition is true. ■",
"Since we know 2 is even, something went wrong.\nBut all the logic after the first line of proof is correct, so it must be that the first line was incorrect. In other words, we were wrong to assume the proposition was false. Thuse the proposition is true. ■",
"Since we know 1 is not even, something went wrong.\nBut all the logic after the second line of proof is correct, so it must be that the second line was incorrect. In other words, we were wrong to assume the proposition was false. Thuse the proposition is true. ■"

}

];
vars={a,b,c};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)


(*Which[key=="1.2", 
{a,b,c,d,e}=nLetters[{"a","z"},5];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This conditional statement being true means there exist numbers @a and @b for which @a,@b∈ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",
"This conditional statement being false means there exist numbers @a and @b for which @a,@b∈ℝ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",
"This conditional statement being true means there exist numbers @a and @b for which @a,@b∉ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2"<>"is false"

}


];
vars={a,b,c,d,e};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)*)


vars=ToString[<|"text"->{question, parta[[1]],partb[[1]]},"vars"->{ parta[[2]],partb[[2]]}, "sol"->{ parta[[3]],partb[[3]]},"keys"->{key2[[1]],key2[[2]]},"choices"->{ parta[[4]],partb[[4]]}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]]}, { parta[[3]],partb[[3]]},{ parta[[4]],partb[[4]]}}


(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";*)

data1="\n"<>"textfghjkl:="<>ToString[<|

"0"->{"Column[{ToString[\"fghjkl. Complete the following proof:\",TraditionalForm]"<>","<>"ToString[\"\"]"<>"}]","Column[{ToString[\"fghjkl. Choose appropriate parts of the proof:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},


(* key=1 contains all kinds of proofs and it variates missing parts *)
"1"-><|
"1.1"->{

(* values needs to be double-string*)
<|
"s1"->ToString["Prove by contradiction.\nProve that (Sqrt[2]) is irrational.",InputForm],

"s2"->"ToString[\"Proof:\n\n Suppose that it is false.\"]",

"s3"->ToString["This statement being false means that (Sqrt[2]) is rational, that is",InputForm],

"s4"->ToString["(Sqrt[2]) = "<>ToString[(("@a")/("@b")), TraditionalForm],InputForm],

"s5"->ToString["where @a and @b are integers and @b ≠ 0. Moreover, let @a and @b have no common divisor > 1. Then",InputForm],

"s6"->ToString[" 2 = "<>ToString[(("@a"^2)/("@b"^2)), TraditionalForm]<>"   ⇒   2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@a"^2,TraditionalForm]<>" ●",InputForm],

"s7"->ToString["Since 2"<>ToString["@b"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@a"^2,TraditionalForm]<>" is even. Then @a is also even(in fact, if @a is odd, then "<>ToString["@a"^2,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that",InputForm],
"s8" -> ToString["@a = 2@c.  ◆",InputForm],
"s9" -> ToString["Substituting ◆ into ●, we get",InputForm],

"s10"->ToString["2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@a"^2,TraditionalForm]<>" = (2"<>ToString["@c)"^2,TraditionalForm]<>"  ⇒   2"<>ToString["@b"^2,TraditionalForm]<>" = 4"<>ToString["@c"^2,TraditionalForm]<>"  ⇒   "<>ToString["@b"^2,TraditionalForm]<>" = 2"<>ToString["@c"^2,TraditionalForm],InputForm],

"s11"->ToString["Since 2"<>ToString["@c"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^2,TraditionalForm]<>" is even. Then @b is also even. We get contradiction therefore we proved that (Sqrt[2]) is irrational. ■",InputForm]
|>
}
,
(*2nd variation *)
"1.2"->{

(* values needs to be double-string*)
<|
"s1"->ToString["Prove by contradiction.\nProve that (4^(1/3)) is irrational.",InputForm],

"s2"->"ToString[\"Proof:\n\n Suppose that it is false.\"]",

"s3"->ToString["This statement being false means that (4^(1/3)) is rational, that is",InputForm],

"s4"->ToString["(4^(1/3)) = "<>ToString[(("@a")/("@b")), TraditionalForm],InputForm],

"s5"->ToString["where @a and @b are integers and @b ≠ 0. Moreover, let @a and @b have no common divisor > 1. Then",InputForm],

"s6"->ToString[" 4 = "<>ToString[(("@a"^3)/("@b"^3)), TraditionalForm]<>"   ⇒   4"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@a"^3,TraditionalForm]<>" ●",InputForm],

"s7"->ToString["Since 4"<>ToString["@b"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@a"^3,TraditionalForm]<>" is even. Then @a is also even(in fact, if @a is odd, then "<>ToString["@a"^3,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that",InputForm],
"s8" -> ToString["@a = 2@c.  ◆",InputForm],
"s9" -> ToString["Substituting ◆ into ●, we get",InputForm],

"s10"->ToString["4"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@a"^3,TraditionalForm]<>" = (2"<>ToString["@c)"^3,TraditionalForm]<>"  ⇒   4"<>ToString["@b"^3,TraditionalForm]<>" = 8"<>ToString["@c"^3,TraditionalForm]<>"  ⇒   "<>ToString["@b"^3,TraditionalForm]<>" = 2"<>ToString["@c"^3,TraditionalForm],InputForm],

"s11"->ToString["Since 2"<>ToString["@c"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^3,TraditionalForm]<>" is even. Then @b is also even. We get contradiction therefore we proved that (4^(1/3)) is irrational. ■",InputForm]
|>
}
,
(*3rd variation *)
"1.3"->{

(* values needs to be double-string*)
<|
"s1"->ToString["Prove by contradiction.\nProve that (Subscript[log, 5])2 is irrational.",InputForm],

"s2"->"ToString[\"Proof:\n\n Suppose that it is false.\"]",

"s3"->ToString["This statement being false means that (Subscript[log, 5])2 is rational, that is",InputForm],

"s4"->ToString["(Subscript[log, 5])2 = "<>ToString[(("@a")/("@b")), TraditionalForm],InputForm],

"s5"->ToString["where @a and @b are integers and @b ≠ 0. Then",InputForm],

"s6"->ToString[ToString[(5^(ToString[(("@a")/("@b")), TraditionalForm])),TraditionalForm]<>" = 2    ⇒  "<>ToString[(5^(ToString["@a", TraditionalForm])),TraditionalForm]<>" = "<>ToString[(2^(ToString["@b", TraditionalForm])),TraditionalForm]<>" ●",InputForm],

"s7"->ToString["Since "<>ToString[(5^(ToString["@a", TraditionalForm])),TraditionalForm]<>" is odd, and "<>ToString[(2^(ToString["@b", TraditionalForm])),TraditionalForm]<>" is even, we obtain a contradiction. Therefore we proved that (Subscript[log, 5])2 is irrational. ■ ",InputForm]
|>
}(*end of 3rd variation*)
,
(*4th variation *)
"1.4"->{

(* values needs to be double-string*)
<|
"s1"->ToString["Prove by contradiction:\nSuppose @a ∈ ℤ. If "<>ToString["@a"^2,TraditionalForm]<>" is even, then @a is even.",InputForm],

"s2"->"ToString[\"Proof:\n\n Suppose that it is false.\"]",

"s3"->ToString["This statement being false means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" is even and @a is not even.",InputForm],

"s4"->ToString["Then "<>ToString["@a"^2,TraditionalForm]<>" is even, and @a is odd." ,InputForm],

"s5"->ToString["Since @a is odd, there is an integer @b for which @a = 2@b + 1.",InputForm],

"s6"->ToString["Then "<>ToString["@a"^2,TraditionalForm]<>" = (2@b + 1)^2 = 4"<>ToString["@b"^2,TraditionalForm]<>" + 4@b + 1 = 2(2"<>ToString["@b"^2,TraditionalForm]<>" + 2@b) + 1, so "<>ToString["@a"^2,TraditionalForm]<>" is odd.",InputForm],

"s7"->ToString["Thus "<>ToString["@a"^2,TraditionalForm]<>" is even and "<>ToString["@a"^2,TraditionalForm]<>" is not even. We obtain a contradiction. Therefore we proved that if "<>ToString["@a"^2,TraditionalForm]<>" is even, then @a is even. ■ ",InputForm]
|>
}(*end of 4th variation*)
,
(*5th variation *)
"1.5"->{

(* values needs to be double-string*)
<|
"s1"->ToString["Prove by contradiction:\nSuppose @a ∈ ℤ. If "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even, then @a is odd.",InputForm],

"s2"->"ToString[\"Proof:\n\n Suppose that it is false.\"]",

"s3"->ToString["This statement being false means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even and @a is not odd.",InputForm],

"s4"->ToString["That is, suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even and @a is even." ,InputForm],

"s5"->ToString["Since @a is even, there is an integer @b for which @a = 2@b.",InputForm],

"s6"->ToString["Then "<>ToString["@a"^2,TraditionalForm]<>"- 2@a + 7 = (2@b)^2 - 2(2@b) + 7 = 2(2"<>ToString["@b"^2,TraditionalForm]<>" - 2@b + 3) + 1, so "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is odd.",InputForm],

"s7"->ToString["Thus "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is both even and odd. We obtain a contradiction. Therefore we proved that if "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even, then @a is odd. ■ ",InputForm]
|>
}(*end of 5th variation*)



|>


|>,InputForm]<>";\n ";


data2="listfghjkl:="<>


ToString[
<|

"1"->{}


|>,InputForm]<>";\n ";

data=ToString[{data1, data2}, InputForm];



canvas3="\n"<>ToString[Hold[canvasFunc3[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data,locations,assoc},

{answers,options}=s;

text=(vars["text"]);
locations=(vars["keys"]); (*get the locations  to place the answers *)
assoc=ToExpression/@text[[2]]; (* this assignment has to happen of the original value of text[[2]] is preserved, see issues in Association*)
Table[assoc[locations[[i]]]=Pane[answers[[i]],BaselinePosition->Scaled[0.2]], {i,1,Length@locations}];


Column[{
ToExpression@text[[1]],
Column@Values[assoc]
}]





]],InputForm]<>"\n ";




variation3=ToExpression[data][[1]]<>ToExpression[data][[2]]<>ToString[Hold[Module[{key,key2,p,x,a,b,c,d,e,f,g,h,i,j,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,pp, vars,text,list,sol,aabbee,k, parta, partb, partc, partd,parte,partf,question,list12,teste,choices},


question=RandomChoice[textfghjkl["0"]];

(*a*)

key=RandomChoice[Keys[textfghjkl["1"]]];
text=RandomChoice[textfghjkl["1"][key]]; (* for proofs this text is actually an association again*)

Which[key=="1.1" , 
{a,b,c}=nLetters[{"a","z"},3];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This statement being true means that (Sqrt[2]) is rational, that is",
"This statement being false means that (Sqrt[2]) is irrational, that is",
"This statement being false means that (Sqrt[2]) is not rational, that is"

},
key2[[i]]=="s4",
{
"(Sqrt[2]) = @a · @b",
"(Sqrt[2]) = @a"<>ToString["@b"^3, TraditionalForm],
"(Sqrt[2]) = "<>ToString[Sqrt["@a"], TraditionalForm]<>ToString["Log@b", TraditionalForm]
}
,
key2[[i]]=="s5",
{
"where @a and @b are integers and @b = 0. Moreover, let @a and @b have no common divisor > 1. Then",
"where @a and @b are integers and @b = 2. Moreover, let @a and @b have no common divisor > 1. Then",
"where @a and @b are integers and @b ≠ (2^0). Moreover, let @a and @b have no common divisor > 1. Then"
},
key2[[i]]=="s6",
{
" 2 = "<>ToString[(("@a"^2)/("@b"^2)), TraditionalForm]<>"   ⇒   3"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@a"^2,TraditionalForm]<>" ●",
" (Sqrt[2]) = "<>ToString[(("@a"^2)/("@b"^2)), TraditionalForm]<>"   ⇒   2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@a"^2,TraditionalForm]<>" ●",
" 2 = "<>ToString[(("@a"^2)/("@b"^2)), TraditionalForm]<>"   ⇒   2"<>ToString["@a"^2,TraditionalForm]<>" = "<>ToString["@b"^2,TraditionalForm]<>" ●"
},
key2[[i]]=="s7",
{
"Since 2"<>ToString["@b"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@a"^2,TraditionalForm]<>" is odd. Then @a is also even(in fact, if @a is odd, then "<>ToString["@a"^2,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that",

"Since 2"<>ToString["@b"^2,TraditionalForm]<>" is odd, it follows that "<>ToString["@a"^2,TraditionalForm]<>" is even. Then @a is also even(in fact, if @a is odd, then "<>ToString["@a"^2,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that",

"Since 2"<>ToString["@b"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@a"^2,TraditionalForm]<>" is even. Then @a is also odd(in fact, if @a is odd, then "<>ToString["@a"^2,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that"

},
key2[[i]]=="s8",
{
"@a = 3@b.  ◆",
"3@a = 2@b.  ◆",
"2@a = 2@b.  ◆"

},
key2[[i]]=="s9",
{
"Substituting ● into ◆, we get",
"Substituting ● into ●, we get",
"Substituting ◆ into ◆, we get"

},

key2[[i]]=="s10",

{
"2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@b"^2,TraditionalForm]<>" = (2"<>ToString["@c)"^2,TraditionalForm]<>"  ⇒   2"<>ToString["@b"^2,TraditionalForm]<>" = 4"<>ToString["@c"^2,TraditionalForm]<>"  ⇒   "<>ToString["@b"^2,TraditionalForm]<>" = 2"<>ToString["@c"^2,TraditionalForm],

"2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@a"^2,TraditionalForm]<>" = (2"<>ToString["@c)"^2,TraditionalForm]<>"  ⇒   2"<>ToString["@b"^2,TraditionalForm]<>" = 4"<>ToString["@c"^2,TraditionalForm]<>"  ⇒   "<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@c"^2,TraditionalForm],

"2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@a"^2,TraditionalForm]<>" = (2"<>ToString["@c)"^2,TraditionalForm]<>"  ⇒   2"<>ToString["@b"^2,TraditionalForm]<>" = "<>ToString["@c"^2,TraditionalForm]<>"  ⇒   "<>ToString["@b"^2,TraditionalForm]<>" = 2"<>ToString["@c"^2,TraditionalForm]

},

key2[[i]]=="s11",

{
"Since "<>ToString["@c"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^2,TraditionalForm]<>" is even. Then @b is also odd. We get contradiction, therefore we proved that (Sqrt[2]) is irrational. ■",

"Since 2"<>ToString["@c"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^2,TraditionalForm]<>" is even. Then @b is also odd. We get contradiction, therefore we proved that (Sqrt[2]) is rational. ■",

"Since 2"<>ToString["@c"^2,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^2,TraditionalForm]<>" is even. Then @b is also even. We get contradiction, therefore we proved that (Sqrt[2]) is rational. ■"

}

];
vars={a,b,c};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)


Which[key=="1.2", 
{a,b,c,d,e}=nLetters[{"a","z"},5];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[


key2[[i]]=="s3",
{
"This statement being true means that (4^(1/3))  is rational, that is",
"This statement being false means that (4^(1/3))  is irrational, that is",
"This statement being false means that (4^(1/3))  is not rational, that is"

},
key2[[i]]=="s4",
{
"(4^(1/3))  = 2@a · @b",
"(4^(1/3))  = @a"<>ToString["@b"^5, TraditionalForm],
"(4^(1/3))  = "<>ToString[Sqrt["@a"], TraditionalForm]<>ToString["Log@b", TraditionalForm]
}
,
key2[[i]]=="s5",
{
"where @a and @b are integers and @b = 0. Moreover, let @a and @b have no common divisor > 1. Then",
"where @a and @b are integers and @b = 1. Moreover, let @a and @b have no common divisor > 1. Then",
"where @a and @b are integers and @b ≠ (2^0). Moreover, let @a and @b have no common divisor > 1. Then"
},
key2[[i]]=="s6",
{
" 4 = "<>ToString[(("@a"^3)/("@b"^3)), TraditionalForm]<>"   ⇒   3"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@a"^3,TraditionalForm]<>" ●",
" (4^(1/3))  = "<>ToString[(("@a"^3)/("@b"^3)), TraditionalForm]<>"   ⇒   4"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@a"^3,TraditionalForm]<>" ●",
" 3 = "<>ToString[(("@a"^4)/("@b"^4)), TraditionalForm]<>"   ⇒   3"<>ToString["@a"^4,TraditionalForm]<>" = "<>ToString["@b"^4,TraditionalForm]<>" ●"
},
key2[[i]]=="s7",
{
"Since 4"<>ToString["@b"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@a"^3,TraditionalForm]<>" is odd. Then @a is also even(in fact, if @a is odd, then "<>ToString["@a"^3,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that",

"Since 4"<>ToString["@b"^3,TraditionalForm]<>" is odd, it follows that "<>ToString["@a"^3,TraditionalForm]<>" is even. Then @a is also even(in fact, if @a is odd, then "<>ToString["@a"^3,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that",

"Since 4"<>ToString["@b"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@a"^3,TraditionalForm]<>" is even. Then @a is also odd(in fact, if @a is odd, then "<>ToString["@a"^2,TraditionalForm]<>" is odd). This means that exists @c ∈ ℤ such that"

},
key2[[i]]=="s8",
{
"@a = 5@b.  ◆",
"@a = 2@a.  ◆",
"2@a = 2@b.  ◆"

},
key2[[i]]=="s9",
{
"Substituting ● into ◆, we get",
"Substituting ● into ●, we get",
"Substituting ◆ into ◆, we get"

},

key2[[i]]=="s10",

{
"4"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@b"^3,TraditionalForm]<>" = (2"<>ToString["@c)"^3,TraditionalForm]<>"  ⇒   4"<>ToString["@b"^3,TraditionalForm]<>" = 8"<>ToString["@c"^2,TraditionalForm]<>"  ⇒   "<>ToString["@b"^3,TraditionalForm]<>" = 2"<>ToString["@c"^3,TraditionalForm],
"4"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@a"^3,TraditionalForm]<>" = (2"<>ToString["@c)"^3,TraditionalForm]<>"  ⇒   4"<>ToString["@b"^3,TraditionalForm]<>" = 4"<>ToString["@c"^3,TraditionalForm]<>"  ⇒   "<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@c"^3,TraditionalForm],
"4"<>ToString["@b"^3,TraditionalForm]<>" = "<>ToString["@a"^3,TraditionalForm]<>" = (2"<>ToString["@c)"^3,TraditionalForm]<>"  ⇒   4"<>ToString["@b"^3,TraditionalForm]<>" = 8"<>ToString["@c"^3,TraditionalForm]<>"  ⇒   "<>ToString["@b"^2,TraditionalForm]<>" = 2"<>ToString["@c",TraditionalForm]

},

key2[[i]]=="s11",

{
"Since "<>ToString["@c"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^3,TraditionalForm]<>" is even. Then @b is also odd. We get contradiction therefore we proved that (4^(1/3)) is irrational. ■",

"Since 2"<>ToString["@c"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^3,TraditionalForm]<>" is even. Then @b is also odd. We get contradiction therefore we proved that (4^(1/3)) is rational. ■",

"Since 2"<>ToString["@c"^3,TraditionalForm]<>" is even, it follows that "<>ToString["@b"^2,TraditionalForm]<>" is even. Then @b is also even. We get contradiction therefore we proved that (4^(1/3)) is rational. ■"

}


];
vars={a,b,c,d,e};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)

Which[key=="1.3", 
{a,b,c,d,e}=nLetters[{"a","z"},5];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This statement being true means that (Subscript[log, 2])5 is rational, that is",
"This statement being false means that (Subscript[log, 5])2 is irrational, that is",
"This statement being false means that (Subscript[log, 5])2 is not rational, that is"

},
key2[[i]]=="s4",
{
"(Subscript[log, 5])2 = @a · 3@b",
"(Subscript[log, 5])2= 2@a"<>ToString["@b"^3, TraditionalForm],
"(Subscript[log, 5])2 = "<>ToString[Sqrt["@a"], TraditionalForm]<>ToString["2Log@b", TraditionalForm]
}
,
key2[[i]]=="s5",
{
"where @a and @b are integers and @b = 1. Then",
"where @a and @b are integers and @b = 2. Then",
"where @a and @b are integers and @b ≠ (2^0). Then"
},
key2[[i]]=="s6",
{
ToString[(2^(ToString[(("@a")/("@b")), TraditionalForm])),TraditionalForm]<>" = 5    ⇒  "<>ToString[(2^(ToString["@a", TraditionalForm])),TraditionalForm]<>" = "<>ToString[(5^(ToString["@b", TraditionalForm])),TraditionalForm]<>" ●",
ToString[(5^(ToString[(("@b")/("@a")), TraditionalForm])),TraditionalForm]<>" = 2    ⇒  "<>ToString[(5^(ToString["@b", TraditionalForm])),TraditionalForm]<>" = "<>ToString[(2^(ToString["@a", TraditionalForm])),TraditionalForm]<>" ●",
"(Subscript[log, 5])"<>ToString[(5^(ToString[(("@a")/("@b")), TraditionalForm])),TraditionalForm]<>" = 2    ⇒  "<>"(Subscript[log, 5])"<>ToString[(5^(ToString["@a", TraditionalForm])),TraditionalForm]<>" = "<>ToString[(2^(ToString["@b", TraditionalForm])),TraditionalForm]<>" ●"
},
key2[[i]]=="s7",
{
"Since "<>ToString[(5^(ToString["@a", TraditionalForm])),TraditionalForm]<>" is even, and "<>ToString[(2^(ToString["@b", TraditionalForm])),TraditionalForm]<>" is odd, we obtain a contradiction, therefore we proved that (Subscript[log, 5])2 is irrational. ■ ",

"Since "<>ToString[(5^(ToString["@a", TraditionalForm])),TraditionalForm]<>" is odd, and "<>ToString[(2^(ToString["@b", TraditionalForm])),TraditionalForm]<>" is even, we obtain a contradiction, therefore we proved that (Subscript[log, 5])2 is rational. ■ ",

"Since (Subscript[log, 5])"<>ToString[(5^(ToString["@a", TraditionalForm])),TraditionalForm]<>" is odd, and "<>ToString[(2^(ToString["@b", TraditionalForm])),TraditionalForm]<>" is even, we obtain a contradiction, therefore we proved that (Subscript[log, 5])2 is irrational. ■ "

}


];
vars={a,b,c,d,e};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)

Which[key=="1.4", 
{a,b,c,d,e}=nLetters[{"a","z"},5];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This statement being false means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" is even and @a is even",
"This statement being true means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" is even and @a is not even",
"This statement being false means that: suppose (Sqrt[3])"<>ToString["@a"^3,TraditionalForm]<>" is even and @a is not even"

},
key2[[i]]=="s4",
{
"Then "<>ToString["@a"^2,TraditionalForm]<>" is even, and @a is even.",
"Then "<>ToString["@a"^2,TraditionalForm]<>" is odd, and @a is odd.",
"Then (Sqrt[3])"<>ToString["@a"^3,TraditionalForm]<>" is even, and @a is even."
}
,
key2[[i]]=="s5",
{
"Since @a is even, there is an integer @b for which @a = 2@b + 1.",
"Since @a is odd, there is an integer @b for which @a = 2@b + 2.",
"Since @a is odd, there is an integer @b for which @a = 2@a + 4."
},
key2[[i]]=="s6",
{
"Then "<>ToString["@a"^2,TraditionalForm]<>" = (2@b + 2\!\(\*SuperscriptBox[\()\), \(2\)]\) = 4"<>ToString["@b"^2,TraditionalForm]<>" + 8@b + 4 = 4("<>ToString["@b"^2,TraditionalForm]<>" + 2@b + 1), so "<>ToString["@a"^2,TraditionalForm]<>" is odd.",

"Then "<>ToString["@a"^2,TraditionalForm]<>" = (2@b + 1\!\(\*SuperscriptBox[\()\), \(2\)]\) = 4"<>ToString["@b"^2,TraditionalForm]<>" + 4@b + 1 = 2(2"<>ToString["@b"^2,TraditionalForm]<>" + 2@b) + 1, so "<>ToString["@a"^2,TraditionalForm]<>" is even.",

"Then "<>ToString["@b"^2,TraditionalForm]<>" = (2@a + 1\!\(\*SuperscriptBox[\()\), \(2\)]\) = 4"<>ToString["@a"^2,TraditionalForm]<>" + 4@a + 1 = 2(2"<>ToString["@a"^2,TraditionalForm]<>" + 2@a) + 1, so "<>ToString["@a"^2,TraditionalForm]<>" is even."
},
key2[[i]]=="s7",
{
"Thus "<>ToString["@a",TraditionalForm]<>" is even and "<>ToString["@a",TraditionalForm]<>" is not even. We obtain a contradiction. Therefore we proved that if "<>ToString["@a"^2,TraditionalForm]<>" is even, then @a is odd. ■ ",

"Thus "<>ToString["@a"^2,TraditionalForm]<>" is odd and "<>ToString["@a"^2,TraditionalForm]<>" is odd. We obtain a contradiction. Therefore we proved that if "<>ToString["@a"^2,TraditionalForm]<>" is even, then @a is even. ■ ",

"Thus "<>ToString["@a",TraditionalForm]<>" is odd and "<>ToString["@a"^2,TraditionalForm]<>" is even. We obtain a contradiction. Therefore we proved that if "<>ToString["@a"^2,TraditionalForm]<>" is odd, then @a is odd. ■ "

}


];
vars={a,b,c,d,e};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)

Which[key=="1.5", 
{a,b,c,d,e}=nLetters[{"a","z"},5];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This statement being false means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even and @a is odd.",

"This statement being false means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is odd and @a is not odd.",

"This statement being false means that: suppose "<>ToString["@a"^2,TraditionalForm]<>" is odd and @a is not odd."

},
key2[[i]]=="s4",
{
"That is, suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even and @a is odd.",
"That is, suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is odd and @a is even.",
"That is, suppose "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is odd and @a is odd."
}
,
key2[[i]]=="s5",
{
"Since @a is even, there is an integer @b for which @a = 2@b + 1.",
"Since @a is odd, there is an integer @b for which @a = 2@b.",
"Since @a is even, there is an integer @b for which @a = 3@b + 3."
},
key2[[i]]=="s6",
{
"Then "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 = (2@b\!\(\*SuperscriptBox[\()\), \(2\)]\) - 2(2@b) + 7 = 2(2"<>ToString["@b"^2,TraditionalForm]<>" - 2@b + 3) + 1, so "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even.",

"Then "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 = (2@b\!\(\*SuperscriptBox[\()\), \(2\)]\) - 2(2@b) + 7 = 2(2"<>ToString["@b"^2,TraditionalForm]<>" - 2@b + 3), so "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is even.",

"Then "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 = (2@b\!\(\*SuperscriptBox[\()\), \(2\)]\) - 2(2@b) + 7 = 2"<>ToString["@b"^2,TraditionalForm]<>" - 2@b + 4, so "<>ToString["@a"^2,TraditionalForm]<>" - 2@a + 7 is odd."
},
key2[[i]]=="s7",
{
"Thus " <> ToString["@a"^2, TraditionalForm] <> " - 2@a + 7 is both even and odd. We obtain a contradiction. Therefore we proved that if " <> ToString["@a"^2, TraditionalForm] <>" - 2@a + 7 is even,then @a is even. ■ ",

"Thus " <> ToString["@a"^2, TraditionalForm] <> " - 2@a + 7 is both even and odd. We obtain a contradiction. Therefore we proved that if " <> ToString["@a"^2, TraditionalForm] <>" - 2@a + 7 is odd, then @a is even. ■ ",

"Thus " <> ToString["@a"^2, TraditionalForm] <> " - 2@a + 7 is both even and odd. We obtain a contradiction. Therefore we proved that if " <>ToString["@a"^2, TraditionalForm] <>" is even, then @a is odd. ■ "

}


];
vars={a,b,c,d,e};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)

(*Which[key=="1.2", 
{a,b,c,d,e}=nLetters[{"a","z"},5];
key2=RandomSample[(Delete[Delete[Keys[text],1],1]),2];

Table[
sol=text[key2[[i]]];
list=Which[

key2[[i]]=="s3",
{
"This conditional statement being true means there exist numbers @a and @b for which @a,@b∈ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",
"This conditional statement being false means there exist numbers @a and @b for which @a,@b∈ℝ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b≠2"<>"is false",
"This conditional statement being true means there exist numbers @a and @b for which @a,@b∉ℤ is true but "<>ToString["@a"^2, TraditionalForm]<>"-4@b=2"<>"is false"

}


];
vars={a,b,c,d,e};
choices=RandomSample[list~Join~{ToExpression@sol},Length[list~Join~{ToExpression@sol}]];
If[i==1,
parta={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices},
partb={StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@text,vars,StringReplace[ToExpression@sol, { "@a"->a,"@b"->b,"@c"->c}],StringReplace[#, { "@a"->a,"@b"->b,"@c"->c}]&/@choices}  ]


,{i,1,2}];

]; (*which*)*)


vars=ToString[<|"text"->{question, parta[[1]],partb[[1]]},"vars"->{ parta[[2]],partb[[2]]}, "sol"->{ parta[[3]],partb[[3]]},"keys"->{key2[[1]],key2[[2]]},"choices"->{ parta[[4]],partb[[4]]}|>,InputForm];

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]]}, { parta[[3]],partb[[3]]},{ parta[[4]],partb[[4]]}}


(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";

solution3=data1<>data2<>ToString[Hold[Module[{x, a,b,c,d,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,g,h,pp,teste,bb1,list123,pos1,t11,t12,t21,t22,s1,s2,sum1,sum2,k},





varsa=vars[[1]];
varsb=vars[[2]];



(*{aa,bb,cc,dd,ee,gg,pp}=varsa;
sol=Solve[ToExpression[bb]*x-ToExpression[cc]*(x-ToExpression[dd])==ToExpression[ee]-ToExpression[gg]*x,x];
*)


body={
{"",""

}, 
{Null ,Null} 
};


Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";


hint3=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},  


body={ 
{""
},
{Null}
};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

This induction problem has all its data inside it for now, we need to clean this up more and make it like the other ones, for now let’s use this version.

data="\n"<>"textfghjkl:="<>ToString[{

(* question *)
{"Column[{ToString[\"fghjkl. Complete the following proof:\",TraditionalForm]"<>","<>"ToString[\"\"]"<>"}]","Column[{ToString[\"fghjkl. Choose appropriate parts of the proof:\",TraditionalForm]"<>","<>"ToString[\" \"]"<>"}]"},
(*{"Column[{ToString[\"fghjkl. .\",TraditionalForm]"<>","<>"\"\""<>"}]",

"Column[{ToString[\"fghjkl. .\",TraditionalForm]"<>","<>"\"\""<>"}]"},*)

(*a*)
{"ToString[\".\",TraditionalForm]",
"ToString[\" .\",TraditionalForm]"}

},InputForm]<>";\n ";


canvas4="\n"<>ToString[Hold[canvasFunc4[s_]:=Module[{vars=ertyuiop,text,answers, options,locs,data,proof,missing,choices},

{answers,options}=s;

{proof,missing,choices}=vars;
proof[[ToExpression@missing]]=answers[[1]];

Column[{
RandomSample[{"4. Complete the following proof:\n","4. Choose appropriate parts of the proof:\n"},1][[1]],
Column[proof]
}]


]],InputForm]<>"\n ";



variation4=data<>ToString[Hold[Module[{p,a,b,c,d,e,f,g,h,i,j,i0,j0,i1,i2,i3,j1,j2,j3,aa,bb,cc,dd,ee, ff, gg, hh, ii, jj,jj0,jj1,jj2,jj3, vars,text,list,sol, parta, partb, partc, partd,parte,partf,question,x,missing,tmp,m,z,table,locs,eq,s1,s2,s3,s4,s5,s6,term, sum, s,ss,ss1,ss2,proof,choices},

Clear[k];
s6=Hold@<|
(*first line*)
"n0"->ToString[5,TraditionalForm],
"step 0"->StringReplace[ToString[ToString[term,TraditionalForm],TraditionalForm],"k"->"n"],
"sum 0"->StringReplace[ToString[sum,TraditionalForm],"k"->"n"],
(*rest*)
"step 1"->ToString[(term/.(k->"1")),TraditionalForm],
"sum 1"->ToString[(sum/.(k->"1")),TraditionalForm],

"step n"->ToString[ToString[term,TraditionalForm],TraditionalForm],

"term n"->ToString[term,TraditionalForm],
"term n+1"->ToString[term/.(k->(k+1)),TraditionalForm],

(*Step n+1*)
"step n+1"->ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k"->ToString@(i)}], {i,1,3}]+"... + "<>ToString[term/.{k->"k"},TraditionalForm]<>"+"<>ToString[term/.{k->"(k+1)"},TraditionalForm],TraditionalForm],

(*Sum n *)
"sum n"->ToString[sum,TraditionalForm],
"sum n EXP"->sum,


(*Sum n + 1 *)
"sum n+1"->ToString[(sum/.{k->(k+1)}),TraditionalForm],
"sum n+1 EXP"->(sum/.{k->(k+1)}),

"step all" -> "(2^k)2 > |from (•)| > 2\!\(\*SuperscriptBox[\(k\), \(\(2\)\(\\ \)\)]\) > (k+1\!\(\*SuperscriptBox[\()\), \(\(2\)\(\\ \\ \)\)]\) \n The last inequality holds since \n 2\!\(\*SuperscriptBox[\(k\), \(\(2\)\(\\ \)\)]\) - (k+1\!\(\*SuperscriptBox[\()\), \(\(2\)\(\\ \\ \)\)]\) = (k-1\!\(\*SuperscriptBox[\()\), \(\(2\)\(\\ \\ \)\)]\)- 2 > 0 , whenever k ⩾ 5.",

(* Subtranct Sum n+1 - Sum n*)
"delta sum"->ToString[ToString[(sum/.{k->"(k+1)"}),TraditionalForm]<>" - ("<>ToString[sum/.{k-> "k"},TraditionalForm]<>")", TraditionalForm],

"delta sum EXP"->ToString[Simplify[(sum/.{k->(k+1)})-sum],TraditionalForm],
(* Expand and simplify Subtranct Sum n+1 - Sum n*)

"Expand delta sum"->ToString[ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[Expand@(sum),TraditionalForm]<>")",TraditionalForm],


"Expand delta sum EXP"->Expand[(sum/.{k->(k+1)})-sum]
|>;


s5=Hold@<|
(*first line*)
"step 0"->ToString[term,TraditionalForm],
"sum 0"->StringReplace[ToString[sum,TraditionalForm],"k"->"n"],
(*rest*)
"step 1"->ToString[(term/.(k->"1")),TraditionalForm],
"sum 1"->ToString[(sum/.(k->"1")),TraditionalForm],

"step n"->ToString[sum,TraditionalForm],

"term n"->ToString[term,TraditionalForm],
"term n+1"->ToString[term/.(k->(k+1)),TraditionalForm],

(*Step n+1*)
"step n+1"->ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k"->ToString@(i)}], {i,1,3}]+"... + "<>ToString[term/.{k->"k"},TraditionalForm]<>"+"<>ToString[term/.{k->"(k+1)"},TraditionalForm],TraditionalForm],

(*Sum n *)
"sum n"->ToString[sum,TraditionalForm],
"sum n EXP"->sum,


(*Sum n + 1 *)
"sum n+1"->ToString[(sum/.{k->(k+1)}),TraditionalForm],
"sum n+1 EXP"->(sum/.{k->(k+1)}),

"step all" -> ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm],
"step all2"->" 3(k^2) + 3k +3 = \[VerticalSeparator] from (•) \[VerticalSeparator] =\n= 3m + 3((k^2) + k + 1) is  divisible by 3",


(* Subtranct Sum n+1 - Sum n*)
"delta sum"->ToString[ToString[(sum/.{k->"(k+1)"}),TraditionalForm]<>" - ("<>ToString[sum/.{k-> "k"},TraditionalForm]<>")", TraditionalForm],

"delta sum EXP"->ToString[Simplify[(sum/.{k->(k+1)})-sum],TraditionalForm],
(* Expand and simplify Subtranct Sum n+1 - Sum n*)

"Expand delta sum"->ToString[ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[Expand@(sum),TraditionalForm]<>")",TraditionalForm],


"Expand delta sum EXP"->Expand[(sum/.{k->(k+1)})-sum]
|>;


s4=Hold@<|
(*first line*)
"step 0"->StringReplace[ToString[ToString[term,TraditionalForm],TraditionalForm],"k"->"n"],
"sum 0"->StringReplace[ToString[sum,TraditionalForm],"k"->"n"],
(*rest*)
"step 1"->ToString["(d/dx)[(x^1)]",TraditionalForm],
"sum 1"->ToString[(sum/.(k->"1")),TraditionalForm],

"step n"->"(d/dx)[(x^k)]",

"term n"->ToString[term,TraditionalForm],
"term n+1"->ToString[term/.(k->(k+1)),TraditionalForm],

(*Step n+1*)
"step n+1"->"(d/dx)[(x^(k + 1))]",
"step all" ->" = (d/dx)[(x^k)x] = |(d/dx)[fg] = f'g + fg' | = ((d/dx)[(x^k)])x + (x^k)((d/dx)[x]) = |from (•)| =\n= \!\(\*SuperscriptBox[\(kx\), \(\(k\)\(-\)\(1\)\(\\ \)\)]\)x + (x^k) = (x^k)(k+1)" ,
"step all2" -> "(x^k)(k+1)",

(*Sum n *)
"sum n"->ToString[sum,TraditionalForm],
"sum n EXP"->sum,


(*Sum n + 1 *)
"sum n+1"->ToString[(sum/.{k->(k+1)}),TraditionalForm],
"sum n+1 EXP"->(sum/.{k->(k+1)}),
(* Subtranct Sum n+1 - Sum n*)
"delta sum"->ToString[ToString[(sum/.{k->"(k+1)"}),TraditionalForm]<>" - ("<>ToString[sum/.{k-> "k"},TraditionalForm]<>")", TraditionalForm],

"delta sum EXP"->ToString[Simplify[(sum/.{k->(k+1)})-sum],TraditionalForm],
(* Expand and simplify Subtranct Sum n+1 - Sum n*)

"Expand delta sum"->ToString[ToString[ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[Expand@(sum),TraditionalForm],TraditionalForm]<>")",TraditionalForm],


"Expand delta sum EXP"->Expand[(sum/.{k->(k+1)})-sum]
|>;


s1=Hold@<|
(*first line*)
"step 0"->StringReplace[ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k"->ToString@i}], {i,1,3}]+"... + "<>ToString[term,TraditionalForm],TraditionalForm],"k"->"n"],
"sum 0"->StringReplace[ToString[sum,TraditionalForm],"k"->"n"],
(*rest*)
"step 1"->ToString[(term/.(k->"1")),TraditionalForm],
"sum 1"->ToString[(sum/.(k->"1")),TraditionalForm],

"step n"->ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k"->ToString@i}], {i,1,3}]+"... + "<>ToString[term,TraditionalForm],TraditionalForm],

"term n"->ToString[term,TraditionalForm],
"term n+1"->ToString[term/.(k->(k+1)),TraditionalForm],

(*Step n+1*)
"step n+1"->ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k"->ToString@(i)}], {i,1,3}]+"... + "<>ToString[term/.{k->"k"},TraditionalForm]<>"+"<>ToString[term/.{k->"(k+1)"},TraditionalForm],TraditionalForm],

(*Sum n *)
"sum n"->ToString[sum,TraditionalForm],
"sum n EXP"->sum,


(*Sum n + 1 *)
"sum n+1"->ToString[(sum/.{k->(k+1)}),TraditionalForm],
"sum n+1 EXP"->(sum/.{k->(k+1)}),


(* Subtranct Sum n+1 - Sum n*)
"delta sum"->ToString[ToString[(sum/.{k->"(k+1)"}),TraditionalForm]<>" - ("<>ToString[sum/.{k-> "k"},TraditionalForm]<>")", TraditionalForm],

"delta sum EXP"->ToString[Simplify[(sum/.{k->(k+1)})-sum],TraditionalForm],
(* Expand and simplify Subtranct Sum n+1 - Sum n*)

"Expand delta sum"->ToString[ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[Expand@(sum),TraditionalForm]<>")",TraditionalForm],


"Expand delta sum EXP"->Expand[(sum/.{k->(k+1)})-sum]
|>;



s2=Hold@<|
(*for n *)

(*first line*)
"step 0"->StringReplace[ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k - 1"->ToString@(i-1)}], {i,1,3}]+"... + "<>StringReplace[ToString[term,TraditionalForm],{"k - 1"->("k-1")}],TraditionalForm],"k"->"n"],
"sum 0"->StringReplace[ToString[sum,TraditionalForm],"k"->"n"],
(*rest*)

"step 1"->ToString[(term/.(k->"1")),TraditionalForm],
"sum 1"->ToString[(sum/.(k->"1")),TraditionalForm],

"step n"->ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k - 1"->ToString@(i-1)}], {i,1,3}]+"... + "(*<>ToString[term,TraditionalForm]<>" + "*)<>StringReplace[ToString[term,TraditionalForm],{"k - 1"->("k-1")}],TraditionalForm],

"term n"->ToString[term,TraditionalForm],
"term n+1"->ToString[term/.(k->(k+1)),TraditionalForm],

(*Step n+1*)
"step n+1"->ToString[Sum[StringReplace[ToString[term,TraditionalForm],{"k - 1"->ToString@(i-1)}], {i,1,3}]+"... + "<>StringReplace[ToString[term,TraditionalForm],{"k - 1"->("k")}],TraditionalForm],


(*Sum n *)
"sum n"->ToString[sum,TraditionalForm],
"sum n EXP"->sum,


(*Sum n + 1 *)
"sum n+1"->ToString[(sum/.{k->(k+1)}),TraditionalForm],
"sum n+1 EXP"->(sum/.{k->(k+1)}),


(* Subtranct Sum n+1 - Sum n*)
"delta sum"->ToString[ToString[ToString[(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[sum,TraditionalForm], TraditionalForm]<>")",TraditionalForm],

"delta sum EXP"->ToString[Simplify[(sum/.{k->(k+1)})-sum],TraditionalForm],
(* Expand and simplify Subtranct Sum n+1 - Sum n*)

"Expand delta sum"->ToString[ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[Expand@sum,TraditionalForm]<>")",TraditionalForm],


"Expand delta sum EXP"->Expand[(sum/.{k->(k+1)})-sum]
|>;




s3=Hold@<|
(*first line*)
"step 0"->StringReplace[ToString["1 + 1 + 1 + ... + "<>ToString[term,TraditionalForm],TraditionalForm],"k"->"n"],
"sum 0"->StringReplace[ToString[sum,TraditionalForm],"k"->"n"],
(*rest*)
"step 1"->ToString[(term/.(k->"1")),TraditionalForm],
"sum 1"->ToString[(sum/.(k->"1")),TraditionalForm],

"step n"->ToString["1 + 1 + 1 ... + "<>ToString[term,TraditionalForm],TraditionalForm],

"term n"->ToString[term,TraditionalForm],
"term n+1"->ToString[term/.(k->(k+1)),TraditionalForm],

(*Step n+1*)
"step n+1"->ToString["1 + 1 + 1 + ... + "<>ToString[term/.{k->"k"},TraditionalForm]<>"+"<>ToString[term/.{k->"(k+1)"},TraditionalForm],TraditionalForm],

(*Sum n *)
"sum n"->ToString[sum,TraditionalForm],
"sum n EXP"->sum,


(*Sum n + 1 *)
"sum n+1"->ToString[(sum/.{k->(k+1)}),TraditionalForm],
"sum n+1 EXP"->(sum/.{k->(k+1)}),


(* Subtranct Sum n+1 - Sum n*)
"delta sum"->ToString[ToString[(sum/.{k->"(k+1)"}),TraditionalForm]<>" - ("<>ToString[sum/.{k-> "k"},TraditionalForm]<>")", TraditionalForm],

"delta sum EXP"->ToString[Simplify[(sum/.{k->(k+1)})-sum],TraditionalForm],
(* Expand and simplify Subtranct Sum n+1 - Sum n*)

"Expand delta sum"->ToString[ToString[ToString[Expand@(sum/.{k->(k+1)}),TraditionalForm]<>" - ("<>ToString[Expand@(sum),TraditionalForm],TraditionalForm]<>")",TraditionalForm],


"Expand delta sum EXP"->Expand[(sum/.{k->(k+1)})-sum]
|>;


eq={
{{k^2,k*(k+1)*(2*k+1)/6},s1,
 s1/.{term->k^2,sum->k*(k+1)*(2*k+1)/6},
s1/.{term->k^2,sum->k*(k+1)*(2*k+1)/2},
s1/.{term->k^2,sum->k*(k+1)*(2*k+1)/3}}
,
{{k,k*(k+1)/2},s1,
s1/.{term->k,sum->k*(k+1)/2},
s1/.{term->k,sum->k*(k+1)/4},
s1/.{term->k,sum->k*(k+2)/2}}
,
{{k^3,(k*(k+1)/2)^2},s1,
 s1/.{term->k^3,sum->(k*(k+1)/2)^2},
s1/.{term->k^3,sum->(k*(k+2)/2)^2},
s1/.{term->k^3,sum->(k*(k+1)/2)}}
,
{{1,k},s3, 
 s3/.{term->1,sum->k},
s3/.{term->1,sum->2(k+1)},
s3/.{term->1,sum->3(k+2)}}
,
{{2*k-1,k^2},s1,
s1/.{term->2*k-1,sum->k^2},
s1/.{term->2*k-1,sum->k^3+1},
s1/.{term->2*k-1,sum->2k^2-1}}
 ,
(*FIXME: make another s1 fix the formatting *)
{{(2^(k-1)),2^k-1},s2,  
s2/.{term->2^(k-1),sum->2^k-1},
s2/.{term->2^(k-1),sum->2^(k+1)+1},
s2/.{term->2^(k-1),sum->2^(k+3)+2}} ,(*s2*)

(*Anna new examples*)
{{k*(k+1),k*(k+1)*(k+2)/3},s1,
 s1/.{term->k*(k+1),sum->k*(k+1)*(k+2)/3},
s1/.{term->k*(k+1),sum->k*(k+1)*(k+2)/2},
s1/.{term->k*(k+1),sum->k*(k+1)*(k+2)/4}},

(*{{1/((3k-2)*(3k+1)),k/(3k+1)},s1},*)
{{k*k!,(k+1)!-1},s1, 
s1/.{term->k*k!,sum->(k+1)!-1},
s1/.{term->k*k!,sum->(k+2)!+1},
s1/.{term->k*k!,sum->(k+3)!+2}},

{{(k+1)*2^k,k*2^(k+1)},s1,
 s1/.{term->(k+1)*2^k,sum->k*2^(k+1)},
s1/.{term->(k+1)*2^k,sum->k*2^(k+2)},
s1/.{term->(k+1)*2^k,sum->k*2^(k+3)}},

(*{{(-1^(k+1)*k^2),(((-1)^(k+1))*k*(k+1))/2},s1},*) (*FIXME fix the formatting(-1) *)
{{1/(k*(k+1)),k/(k+1)},s1, 
s1/.{term->1/(k*(k+1)),sum->k/(k+1)},
s1/.{term->1/(k*(k+1)),sum->k/(k+2)},
s1/.{term->1/(k*(k+1)),sum->2*k/(k+1)}},
(*examples Derivative*)
(*{{"(d/dx)[(x^n)]",k*"x"^(k-1)},s4} ,*)
(*examples "divisible by"*)
(*{{3,k^3 + 2k},s5},*)
(*examples with inequality*)
{{(2^k),(k^2)},s6, s6/.{term->(2^k),sum->(k^2)}, s6/.{term->(2^k),sum->(((k+1))^2)}, s6/.{term->(2^k),sum->(((k-1))^2)}}

};



{{term, sum},s,ss,ss1,ss2}=RandomChoice@eq;

{{term, sum},s,ss,ss1,ss2}={{term, sum},s,ReleaseHold@ss,ReleaseHold@ss1,ReleaseHold@ss2};

x={ss,ss1,ss2};

(*TODO: make proof an Association *)
proof=Table[{
"Prove by induction: "<>If[s===s5,"",(x[[i]])["step 0"]<>If[s===s6," > ",If[s===s3,"(n times) = ","="]]]<>(x[[i]])["sum 0"]<>If[s===s5," is divisible by "<>(x[[i]])["step 0"],""]<>If[s===s6," for all n ⩾ "<>(x[[i]])["n0"]," for all n ∈ (SubPlus[ℕ])"],
"Proof:",
Spacer[100],
"Step 1: n=1",
If[s===s6,(x[[i]])["sum 1"]<>" < "<>(x[[i]])["step 1"],(x[[i]])["sum 1"]<>"="<>(x[[i]])["step 1"]]<>If[s===s5," is divisible by "<>(x[[i]])["step 0"],""],
If[s===s4,"1 =  1"],
Spacer[100],
"Step 2:",
"Assume that it is true for n=k:",
If[s===s5,
(x[[i]])["sum n"]<>" is divisible by "<>(x[[i]])["step 0"]<>"\n"<>(x[[i]])["sum n"]<>" = "<>(x[[i]])["step 0"]<>"m, where m is positive integer."<>"      (•)"
,
(x[[i]])["step n"]<>If[s===s6," > "," = "]<>(x[[i]])["sum n"]<>"      (•)"],

"\nProve that it is true for n=k+1: ",
If[s===s6,
(x[[i]])["term n+1"]<>" = "<>(x[[i]])["step all"]<>"\n" (*ANNA I changed first part into term n+1 (before was wrong)*)
,
If[s===s5,
(x[[i]])["sum n+1"]<>" = "<>(x[[i]])["step all"]<>" = ("<>(x[[i]])["step n"]<>") + "<>(x[[i]])["step all2"]
,
(x[[i]])["step n+1"]<>
If[s===s4,
(x[[i]])["step all"]
,
"=("<>(x[[i]])["step n"]<>") + "<>(x[[i]])["term n+1"]<>" = \[VerticalSeparator] from (•) \[VerticalSeparator] ="]
]
],
If[s===s6,Plot[{(k-1)^2 - 2, 0} , {k,-7, 7},PlotLegends->{"(k-1)^2 - 2","0"}],If[s===s5,"",If[s===s4,"","=("<>(x[[i]])["sum n"]<>")+"<>(x[[i]])["term n+1"]]]],

If[s===s6,"",If[s===s5,"","\nNote that after appropriate transformation of above result, we get that: "]],
If[s===s6,"",If[s===s5,"",If[s===s4,(x[[i]])["step all2"],"("<>(x[[i]])["sum n"]<>")+"<>(x[[i]])["term n+1"]]<>" = " <>(x[[i]])["sum n+1"]]],

If[s===s6,"",If[s===s5,"",If[s===  s4 ,"","\nWe can also consider delta of sums for k+1 terms and k terms, to check if difference is exactly k+1 element:"]]],
If[s===s6,"",If[s===s5,"",If[s=== s4 ,"",(x[[i]])["delta sum"]<>"="<>(x[[i]])["Expand delta sum"]<>"="]]],
If[s===s6,"",If[s===s5,"",If[s=== s4 ,"","="<>(x[[i]])["delta sum EXP"]]]],

"\nTherefore, the proof is complete since it has been shown to be true for n = 1, n = k, and n = k + 1, so",
If[s===s5,"",(x[[i]])["step 0"]<>If[s===s6," > ",If[s===s3,"(n times) = ","="]]]<>(x[[i]])["sum 0"]<>If[s===s5," is divisible by "<>(x[[i]])["step 0"],""]<>If[s===s6," for all n ⩾"<>(x[[i]])["n0"]," for all n ∈ (SubPlus[ℕ])"]
},{i,1,3}];


If[s===s6,list={5,10,20},list={5,10,13,15,18,20}];

question=qRandList[textfghjkl[[1]]];

text=qRandList[textfghjkl[[2]]];

(*missing=ToString@RandomInteger[{3,Length@proof[[1]]}];*)
missing=ToString@(RandomChoice@list);
choices=RandomSample[{missing->(proof[[1]][[ToExpression@missing]]),(missing+1)->(proof[[2]][[ToExpression@missing]]),(missing+2)->(proof[[3]][[ToExpression@missing]])},3];
vars=ToString[{proof[[1]],missing,choices},InputForm];

(*question=StringReplace[question, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#i0"->i0,"#i1"->i1,"#j0"->jj0,"#j1"->jj1,"#i2"->i2,"#j2"->jj2,"#i3"->i3,"#j3"->jj3}];*)

(*parta={StringReplace[text, {"@a"->aa,"@b"->bb,"#c"->c,"#d"->d,"#e"->e,"#i1"->i1,"#j1"->j1,"#i2"->i2,"#j2"->j2,"#j3"->j3}],vars,sol} ;*)

(*sol=ToString[proof[[ToExpression@missing]],InputForm];*)
sol=missing;
parta={text,vars,sol};


{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{parta[[2]]}, {parta[[3]]}}



(* it has to be InputForm or ToExpression fails *)
]],InputForm]<>"\n ";


solution4=data<>ToString[Hold[Module[{aa,bb,cc,dd,ee, c,d,e,ff,f, gg, hh, ii, jj,i0,j0,i3,i1,i2,j1,j2,j3, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP, varsa, varsb, varsc,varsd,varse,varsf,index,missing,m,z,table, locs,toeq},


(*varsa=vars[[1]];*)
(*varsb=vars[[2]];
varsc=vars[[3]];
varsd=vars[[4]];
varse=vars[[5]];
varsf=vars[[6]];*)

body={{},{}};

Panel[Grid[Transpose[body]]] 

(*"Anna switch a and c"*)

]],InputForm]<>"\n ";


hint4=ToString[Hold[Module[{aa,bb,cc,dd,ee, ff, gg, hh, ii, jj, text,list,sol, body={},vars=ertyuiop,options=ERTYUIOP},


body={{},{}};

Panel[Grid[Transpose[body]]]

]],InputForm]<>"\n ";

PRACTICE

proc1=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation1,hint1,solution1,canvas1},InputForm]<>";\n";
proc2=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation2,hint2,solution2,canvas2},InputForm]<>";\n";
proc3=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation3,hint3,solution3,canvas3},InputForm]<>";\n";
proc4=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation4,hint4,solution4,canvas4},InputForm]<>";\n";

ToExpression@libGUI;
ToExpression@libIO;
ToExpression@libML;
panelsMIX={ StringReplace[qCanvas0,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO4,errNO4}","inputsize0"->"{5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvasPOP0,{"pn0"->ToString[2],"proc0"->proc2,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO31,errNO31}","inputsize0"->"{5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvasPOP0,{"pn0"->ToString[3],"proc0"->proc3,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO31,errNO31}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvasPOPINDUCTION,{"pn0"->ToString[4],"proc0"->proc4,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC<>"\n"<>libML<>"\n"),"level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"2","IO00"->"qClick","logo"->ToString[,InputForm],"err0"->"{errNO3,errNO3,errNO3,errNO3,errNO3,errNO3,errNO3,errNO3}"}]


};

TEST

proc1=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation1,hint1,solution1,canvas1},InputForm]<>";\n";
proc2=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation2,hint2,solution2,canvas2},InputForm]<>";\n";
proc3=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation3,hint3,solution3,canvas3},InputForm]<>";\n";
proc4=ToString[{ToString[Hold[Module[{},"level"]],InputForm],variation4,hint4,solution4,canvas4},InputForm]<>";\n";



ToExpression@libGUI;
ToExpression@libIO;
ToExpression@libML;
panelsMIXTEST={ 

StringReplace[qCanvas0,{"pn0"->ToString[1],"proc0"->proc1,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO4,errNO4}","inputsize0"->"{5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"1","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvasPOP0,{"pn0"->ToString[2],"proc0"->proc2,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO31,errNO31}","inputsize0"->"{5,5}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"1","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvasPOP0,{"pn0"->ToString[3],"proc0"->proc3,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"err0"->"{errNO31,errNO31}","level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"2","diag00"->"1","IO00"->"qClick","logo"->ToString[,InputForm]}],

StringReplace[qCanvasPOPINDUCTION,{"pn0"->ToString[4],"proc0"->proc4,"libs"->(libLIST<>"\n"<>libNAMES<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC<>"\n"<>libML<>"\n"),"level00"->ToString[{1,1,{}}],"max0"->"3","mult0"->"1","diag00"->"1","IO00"->"qClick","logo"->ToString[,InputForm],"err0"->"{errNO3,errNO3,errNO3,errNO3,errNO3,errNO3,errNO3,errNO3}"}],


StringReplace[qSendLocal,{"libs"->(libLIST<>"\n"<>libIO<>"\n"<>libERR<>"\n"<>libMISC),"path0"->"\"\"","examName0"->"\"MET CS248, Homework 1\"","examName20"->"\"MET CS248, Homework 1\"","examIDString20"->"\"MET CS248, Homework 1\"","logo"->ToString[,InputForm],"weights0"->"{1,1,1,1,1,1,1}"}]


};

HOMEWORK_CDF

CDFDeploy[ToFileName[{$UserDocumentsDirectory},"cs248_homework_PRAC.cdf"],Column[Table[ReleaseHold[ToExpression[panelsMIX[[i]]]],{i,1,Length[panelsMIX]}]],
"Method"->"Standalone"];

CDFDeploy[ToFileName[{$UserDocumentsDirectory},"cs248_homework_1.cdf"],Column[Table[ReleaseHold[ToExpression[panelsMIXTEST[[i]]]],{i,1,Length[panelsMIXTEST]}]],
"Method"->"Standalone"];

TEST AREA

Column[Table[ReleaseHold[ToExpression[panelsMIXTEST[[i]]]],{i,1,Length[panelsMIXTEST]}]]

ReleaseHold[ToExpression[panelsMIX[[3]]]]

Column[Table[ReleaseHold[ToExpression[panelsMIX[[i]]]],{i,1,Length[panelsMIX]}]]