LIBS

(*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";*)

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

Module Area

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

(*fghjkl. removed*)


"0"-><|
"1.1"->{"Column[{ToString[\" \"]"<>"}]"}
|>
,
(* let's use key as the option *)
"1"-><|
"1.1"->{"Column[{ToString[\"1. The country wants to estimate the proportion of votes who will need spacial election facitilies. Suppose a sample of #c votes was taken. If #d need spacial election facilities, calculate a #a% confidence interval for the proportion.\"]"<>"}]",
"Column[{ToString[\"1. The country wants to estimate the proportion of votes who will need spacial election facitilies. Calculate a #a% confidence interval for the proportion if You know that for a sample of #c votes, #d need spacial election facilities.\"]"<>"}]",
"Column[{ToString[\"1. The mayor of New York wants to estimate the proportion of votes who will need spacial election facitilies in  elections for mayor. Assume a sample of #c votes was taken. If #d need spacil election facilities, calculate a #a% confidence interval for the proportion.\"]"<>"}]"}
|>
,
"2"-><|

(*"2.1"->{"Column[{ToString[\"2. If (OverBar[X])=#a, σ=#b and n=#c, the #d% confidence interval estimate for the population mean μ is:\",TraditionalForm]"<>"}, Alignment->Left]"}*)

"2.1"->{"Column[{ToString[\"2. In the past, the proportion of votes, who needed spacial election facilities in a country has been estimated to be #c%. The country clerk wants to construct a #a% confidence interval for the population proportion which extends at most #d to either side of the sample propr\",TraditionalForm]"<>"}, Alignment->Left]"}
|>

,
"3"-><|
"3.1"->{"Column[{ToString[\"3. Determine the critical value of t in the following circumstances:\"]"<>","<>"ToString[\"          1-α = #a, n=#b.\",TraditionalForm]"<>","<>"ToString[\"Round your answer to 4 decimal places.\"]}]"}

|>
,

(*A study from the previous year on a sample of size 300 showed that 50% of office workers respond to e-mail within an hour ±0.05. What is the confidence level of this estimation?*)
"4"-><|
"4.1"->{"Column[{ToString[\"4. It is desired to estimate the mean total compensation of CEOs in the Service industry. Data were randomly collected from #a CEOs and the #b% confidence interval was calculated to be ($#c, $#d). Is the following statement correct?\",TraditionalForm]"<>"}, Alignment->Left]"},

"4.2"->{"Column[{ToString[\"4. The department of motor vehicles in Toronto needs to estimate the mean total commute  distance driven by the motorists. #a drivers randomly selected, and the #b% confidence interval was calculated to be (#ckm, #dkm). Verify the following statement?\",TraditionalForm]"<>"}, Alignment->Left]"
},

"4.3"->{"Column[{ToString[\"4. The Ministry of Public Health in Toronto needs to estimate the mean total weight  of Torontonians. #a random individuals were weighted, and the #b% confidence interval was computed to be (#ckg, #dkg). Is the following statement true or false?\",TraditionalForm]"<>"}, Alignment->Left]"
}
|>


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



data2="listfghjkl:="<>


ToString[{"",""


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

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



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


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

{Image[,ImageSize->125]},
{Image[]},   
{"Quiz 1,January 2016"},
{Image[]},
{"id"},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[2]]}}]},
{Grid[{{"x1",Rasterize@" ⩽p⩽ ","x2"}}]},(*ANNA: I changed Z into p *)
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[3]]}}]},
{Grid[{{"x3",Rasterize@" n = ","x4"}}]},
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[4]]}}]},
{Grid[{{Rasterize@ToString["t=±",TraditionalForm],"x5"}}]},

text2=vars["vars"][[4]][[5]];
{Image[]},
{Grid[{{Rasterize@ToExpression@text[[5]]}}]},
{Image[]},
{Grid[{{Rasterize@text2}}]},
{Grid[{{"x6"}}]}

},Spacings->{0,3}]


]],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,pr,r,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,sol2,sol3,t},


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

(*a*)

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


Which[key=="1.1", 
a=ToString@(RandomChoice@{99, 95,90,85,80,75,70,65,60});
b=ToString@N[(ToExpression@a)/100];
c=ToString@(RandomSample[Range[4,10],1][[1]]*100);
d=ToString@(ToExpression@c - RandomSample[Range[10,20]][[1]]*10);
pr=ToString@(N[ToExpression@d / ToExpression@c]);
vars={a,b,c,d,p,r};
r={x/.NSolve[CDF[NormalDistribution[0,1],x]== (1-ToExpression@b)/2,{x}, Reals][[1]],x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]]};
sol={ToExpression@pr+r[[1]]*Sqrt[ToExpression@pr*(1-ToExpression@pr)/ToExpression@c],ToExpression@pr+r[[2]]*Sqrt[ToExpression@pr*(1-ToExpression@pr)/ToExpression@c]};
(*question=StringReplace[question, { "#a"->a}];*)
parta={StringReplace[text, { "#a"->a,"#b"->b, "#c"->c,"#d"->d}],vars,sol} ;

];



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

Which[key=="2.1", 
a=ToString@(RandomChoice@{99, 95,90,85,80,75,70,65,60});
b=ToString@N[(ToExpression@a)/100];
c=ToString@(RandomSample[Range[11,19],1][[1]]);
d=ToString@(RandomSample[Range[4,9],1][[1]]*0.01);
vars={a,b,c,d};
r=x/.NSolve[CDF[NormalDistribution[0,1],x]==1- (1-ToExpression@b)/2,{x}, Reals][[1]];
e=Ceiling[((ToExpression@r)^2 * ToExpression@c*(1-ToExpression@c))/((ToExpression@d)^2)];
sol={e,e};

partb={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;

];


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

Which[key=="3.1", 

a=ToString@RandomChoice[{1-0.90, 1-0.95, 1-0.975, 1-0.99, 1-0.995, 1-0.999}];
b=ToString@RandomInteger[{5,30}];

vars={a,b};
sol={sol2=NSolve[CDF[StudentTDistribution[ToExpression@b],x]== (ToExpression@a)/2,{x}, Reals];
t=x/.sol2[[1]],sol2=NSolve[CDF[StudentTDistribution[ToExpression@b],x]==1- (ToExpression@a)/2,{x}, Reals];
t=x/.sol2[[1]]};

partc={StringReplace[text, { "#a"->(ToString@(1-ToExpression@a)),"#b"->b}],vars,sol} ;

];


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

Which[key=="4.1", 

a=ToString@RandomInteger[{10,20}];
b=ToString@RandomInteger[{75,99}];
c=ToString@RandomInteger[{1000000,5000000}];
d=ToString@(ToExpression[c]+RandomInteger[{100000,500000}]);



list=RandomChoice@{

{StringReplace["#b% of the sampled total compensation values fall between $#c, $#d.", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"False","false","FALSE","F"}},

{StringReplace["We are #b% confident that the mean of the sampled CEOs falls in the interval $#c to $#d.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"False","false","FALSE","F"}},

{StringReplace["In the population of Service industy CEOs, #b% of them will have total compensations that fall in the interval $#c to $#d.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"False","false","FALSE","F"}},

{StringReplace["We are #b% confident that the mean total compensation of all CEOs in the Service industry falls in the interval $#c to $#d.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"T","true","TRUE"}}
};



vars={a,b,c,d,list[[1]]};
sol={list[[2]]};

partd={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;
,


key=="4.2", 

a=ToString@RandomInteger[{100,200}];
b=ToString@RandomInteger[{75,99}];
c=ToString@RandomInteger[{100,200}];
d=ToString@(ToExpression[c]+RandomInteger[{10,50}]);



list=RandomChoice@{

{StringReplace["#b% of the sampled total distance values fall between #ckm, #dkm.", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"False","false","FALSE","F"}},

{StringReplace["We are #b% confident that the mean of the sampled distances falls in the interval #ckm to #dkm.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"False","false","FALSE","F"}},

{StringReplace["For all drivers in Toronto, #b% of them will have total commuting distance that fall in the interval #ckm to #dkm.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"False","false","FALSE","F"}},

{StringReplace["We are #b% confident that the mean total distance of all Toronto drivers fall in the interval #ckm to #dkm.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"T","true","TRUE"}}
};



vars={a,b,c,d,list[[1]]};
sol={list[[2]]};

partd={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;
,

key=="4.3", 

a=ToString@RandomInteger[{1000,2000}];
b=ToString@RandomInteger[{75,99}];
c=ToString@RandomInteger[{50,100}];
d=ToString@(ToExpression[c]+RandomInteger[{5,10}]);



list=RandomChoice@{

{StringReplace["#b% of the sampled total weight values fall between #ckg, #dkg.", { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],
{"False","false","FALSE","F"}},

{StringReplace["We are #b% confident that the mean of the sampled weights falls in the interval #ckg to #dkg.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"False","false","FALSE","F"}},

{StringReplace["For all Torontonians, #b% of them will have total weight that fall in the interval #ckg to #dkg.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"False","false","FALSE","F"}},

{StringReplace["We are #b% confident that the mean total weight of all Torontonians fall in the interval #ckg to #dkg.",{ "#a"->a,"#b"->b,"#c"->c,"#d"->d}],{"T","true","TRUE"}}
};



vars={a,b,c,d,list[[1]]};
sol={list[[2]]};

partd={StringReplace[text, { "#a"->a,"#b"->b,"#c"->c,"#d"->d}],vars,sol} ;

];



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

{StringReplace[ToString[canvasZ,InputForm],{"ertyuiop"->vars}],{ parta[[2]],partb[[2]],partc[[2]],partd[[2]]}, { parta[[3]],partb[[3]],partc[[3]],partd[[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 ";

Cloud Area

(* all err functions need to be called here since the Send is entirely happens in one unit *)
send[a0_]:=Module[{a,b,c,d,sol0,canvas0,err,err2,err3,err4,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,n,xbar,d1,d2,x,df,col, body={}},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
body={a0["id"]};

μ=0;σ=1;
{canvas,vars,sol}=ReleaseHold[ToExpression[a0["q"],InputForm]];
sol1=Sort[(ToExpression@sol)[[1]],Less];

err=If[Norm[{ToExpression@(a0["x1"]),ToExpression@(a0["x2"])}-sol1]<0.01, 1, 0];

g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,sol1[[1]],sol1[[2]]},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{0,0},FillingStyle->{Red}];



sol2=Sort[(ToExpression@sol)[[2]],Less];
err2=If[Norm[{ToExpression@(a0["x3"]),ToExpression@(a0["x4"])}-sol2]<0.01, 1, 0];

AppendTo[body, err];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[],
" ",
"1. "<>If[err==1, "Correct","Incorrect"],"Your answers:",Row@{a0["x1"],", ",a0["x2"]},"Solutions:",Row@{sol1[[1]],", ",sol1[[2]]},Show[g1,g2,ImageSize->400],

"2. "<>If[err2==1, "Correct", "Incorrect"],"Your answers:",Row@{a0["x3"],", ",a0["x4"]},"Solutions:",Row@{sol2[[1]],", ",sol2[[2]]},"Visualization:",Rasterize@"See the Red dot, that is ((OverBar[X]),(OverBar[X])), the yellowish region trapped between the two lines shows how spread the samples could be due to σ.",

{a,b,c,d}=vars[[2]];
σ=ToExpression@b;  (*ToExpression has to be here since b is String *)
n=ToExpression@c;
xbar=ToExpression@a;
{d1,d2}=sol[[2]];
g3=DensityPlot[PDF[NormalDistribution[μ,σ],x], {x,-xbar,2*xbar},{μ,0* d1/2,d2*1.5},PlotRange->Full,PlotPoints->40,PlotLegends->Automatic,FrameLabel->{"x","μ"},AxesLabel->{0,0}];

g7=Plot3D[PDF[NormalDistribution[μ,σ],x], {x,-xbar,2*xbar},{μ, 0* d1/2,d2*1.5},PlotRange->Full,AxesLabel->{"x","μ", "P"},PlotPoints->40, ImageSize->400];
g4=Plot [d1, {x,-xbar,2*xbar}];
g5=Plot [ d2, {x,-xbar,2*xbar}];
g6=Graphics[{Red,Point[{xbar,xbar}]}];

Show[g3,g4,g5,g6, ImageSize->400],
" ",
"3D visualization of a Normal distribution as μ varies: (x, μ, P(x)) ≈ N(μ, σ)",
g7,

" ",

sol3=(ToExpression@sol)[[3]];
err3=If[ToExpression@(a0["x5"])-(Abs[sol3[[1]]])<0.01, 1, 0];
{a,b}=ToExpression@vars[[3]];
df=b;
g8=Plot[PDF[StudentTDistribution[df],x],{x,-8,8},Filling->Axis,PlotRange->All];
g9=Plot[PDF[StudentTDistribution[df],x],{x,sol3[[2]],8},Filling->Axis,PlotStyle->Red, AxesOrigin->{0,0},PlotRange->All];
g10=Plot[PDF[StudentTDistribution[df],x],{x,-8,sol3[[1]]},Filling->Axis,PlotStyle->Red, AxesOrigin->{0,0},PlotRange->All];
"3. "<>If[err==1, "Correct","Incorrect"],
"Your answers:",a0["x5"],"Solutions:",Row@{"±",sol3[[1]]},
Show[g8,g9,g10, ImageSize->400],
" ",
(*sol4=(sol)[[4]],*) (* no ToExpression for text *)
sol4=(ToExpression@sol)[[4]];
"4. "<>If[MemberQ[sol4[[1]],a0["x6" ]]==True, err4=1;"Correct",err4=0;"Incorrect"],

" ",
" ",
" "

 };

AppendTo[body,err3];
AppendTo[body,err4];


resF=URLFetch["http://symbolicexams.lossofgenerality.com/wp-content/plugins/test-receiver/results.php","Parameters"->{"results"->(ToString@body)},"ReadTimeout"->10,"ConnectTimeout"->50,"Method"->"POST"];


HTTPRedirect@CloudExport[Column@col,"PNG",Permissions->"Public"][[1]]
];


(* all err functions need to be called here since the Send is entirely happens in one unit *)
sendLOCAL[a0_]:=Module[{a,b,c,d,sol0,canvas0,err,err2,err3,err4,resF,canvas,vars,sol,sol1,sol2,sol3,sol4,μ,σ,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,n,xbar,d1,d2,x,df,col, body={}},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
body={a0["id"]};

μ=0;σ=1;
{canvas,vars,sol}=ReleaseHold[ToExpression[a0["q"],InputForm]];
sol1=Sort[(ToExpression@sol)[[1]],Less];

err=If[Norm[{ToExpression@(a0["x1"]),ToExpression@(a0["x2"])}-sol1]<0.01, 1, 0];

g1=Plot[PDF[NormalDistribution[μ,σ],x],{x,-7,7},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{0,0}];
g2=Plot[PDF[NormalDistribution[μ,σ],x],{x,sol1[[1]],sol1[[2]]},Filling->Axis,PlotLabel->"Normal Distribution\n"<>"μ="<>ToString[μ]<>", σ="<>ToString[σ], PlotRange->Full,AxesOrigin->{0,0},FillingStyle->{Red}];



sol2=Sort[(ToExpression@sol)[[2]],Less];
err2=If[Norm[{ToExpression@(a0["x3"]),ToExpression@(a0["x4"])}-sol2]<0.01, 1, 0];

AppendTo[body, err];
AppendTo[body, err2];

col={

Image[,ImageSize->125],
" ",
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[],
" ",
"1. "<>If[err==1, "Correct","Incorrect"],"Your answers:",Row@{a0["x1"],", ",a0["x2"]},"Solutions:",Row@{sol1[[1]],", ",sol1[[2]]},Show[g1,g2,ImageSize->400],

"2. "<>If[err2==1, "Correct", "Incorrect"],"Your answers:",Row@{a0["x3"],", ",a0["x4"]},"Solutions:",Row@{sol2[[1]],", ",sol2[[2]]},"Visualization:",Rasterize@"See the Red dot, that is ((OverBar[X]),(OverBar[X])), the yellowish region trapped between the two lines shows how spread the samples could be due to σ.",

{a,b,c,d}=vars[[2]];
σ=ToExpression@b;  (*ToExpression has to be here since b is String *)
n=ToExpression@c;
xbar=ToExpression@a;
{d1,d2}=sol[[2]];
g3=DensityPlot[PDF[NormalDistribution[μ,σ],x], {x,-xbar,2*xbar},{μ,0* d1/2,d2*1.5},PlotRange->Full,PlotPoints->40,PlotLegends->Automatic,FrameLabel->{"x","μ"},AxesLabel->{0,0}];

g7=Plot3D[PDF[NormalDistribution[μ,σ],x], {x,-xbar,2*xbar},{μ, 0* d1/2,d2*1.5},PlotRange->Full,AxesLabel->{"x","μ", "P"},PlotPoints->40, ImageSize->400];
g4=Plot [d1, {x,-xbar,2*xbar}];
g5=Plot [ d2, {x,-xbar,2*xbar}];
g6=Graphics[{Red,Point[{xbar,xbar}]}];

Show[g3,g4,g5,g6, ImageSize->400],
" ",
"3D visualization of a Normal distribution as μ varies: (x, μ, P(x)) ≈ N(μ, σ)",
g7,

" ",

sol3=(ToExpression@sol)[[3]];
err3=If[ToExpression@(a0["x5"])-(Abs[sol3[[1]]])<0.01, 1, 0];
{a,b}=ToExpression@vars[[3]];
df=b;
g8=Plot[PDF[StudentTDistribution[df],x],{x,-8,8},Filling->Axis,PlotRange->All];
g9=Plot[PDF[StudentTDistribution[df],x],{x,sol3[[2]],8},Filling->Axis,PlotStyle->Red, AxesOrigin->{0,0},PlotRange->All];
g10=Plot[PDF[StudentTDistribution[df],x],{x,-8,sol3[[1]]},Filling->Axis,PlotStyle->Red, AxesOrigin->{0,0},PlotRange->All];
"3. "<>If[err==1, "Correct","Incorrect"],
"Your answers:",a0["x5"],"Solutions:",Row@{"±",sol3[[1]]},
Show[g8,g9,g10, ImageSize->400],
" ",
(*sol4=(sol)[[4]],*) (* no ToExpression for text *)
sol4=(ToExpression@sol)[[4]];
"4. "<>If[MemberQ[sol4[[1]],a0["x6" ]]==True, err4=1;"Correct",err4=0;"Incorrect"],

" ",
" ",
" "

 };

AppendTo[body,err3];
AppendTo[body,err4];


local`body=Column@{body,col}
];





genFormLOCAL[]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={
{"x1",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x3",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,
"q"->"String"};

FormFunction[ans,sendLOCAL,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x1"->#["x1"],"x2"->#["x2"],"x3"->#["x3"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"id"->#["id"]}]


], FormTheme -> "Blue"]["q"->f[]]






];

genForm[a0_]:=Module[{a,sol0,canvas0,err,resF,canvas,vars,sol,f,ans},

ToExpression@libLIST; (*these have to be here *)
ToExpression@libERR;
f[]:=(ToString[ReleaseHold[ToExpression[StringReplace[variation1,{"canvasZ"->canvas1,"fghjkl"->ToString[1]}]]],InputForm]); (* InputForm must be here or some problems occurs in ToExpression@variation *)
ans={
{"x1",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x2",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x3",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "", "Help" -> ""|>,
{"x4",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x5",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "",  "Help" -> ""|>,
{"x6",""}-><|"Required"->True,"Interpreter"->"String","Hint" -> "true, false, T, F",  "Help" -> ""|>,
{"id",""}-><|"Interpreter"->"String","Help" -> "","Hint"->"Enter Student ID"|>,
"q"->"String"};

HTTPRedirect@CloudDeploy[FormFunction[ans,send,  AppearanceRules-><|"SubmitLabel" -> "Send Answers"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

{canvas,vars,sol}=ReleaseHold[ToExpression[Setting@#["q"][[1]][[1]][[2]][[1]]]];

ReleaseHold[ToExpression[canvas,InputForm]/.{"x1"->#["x1"],"x2"->#["x2"],"x3"->#["x3"],"x4"->#["x4"],"x5"->#["x5"],"x6"->#["x6"],"id"->#["id"]}]


], FormTheme -> "Blue"]["q"->f[]], 

Permissions->"Public"][[1]]







];

Deploy Area

DeleteFile[c];
c=CloudDeploy[FormFunction[{},
genForm,  AppearanceRules-><|"SubmitLabel" -> "Start"|>,

FormLayoutFunction->Function[


(* we need to use sol in send[] in order to see if the student input is correct or not?*)

Column[{Image[,ImageSize->125],
Spacer@100,
"F16 QMS 202",
"Practice Questions for Lecture 2\nJanuary 2016",
Image[,ImageSize->5],
Spacer@100,

"Press Start button to start the test"
}]


], FormTheme -> "White"], 

Permissions->"Public"]

LOCAL TEST AREA

The local form is slow, take a second to refresh the input fields. Also the Send Answer Button might not chave colour properly.

genFormLOCAL[]

local`body