# Math question for solving systems

I will post my current code below. The current code works perfectly for having students solve for systems. The problem is that every once in a whole a no solution situation will arise and I want that to happen, but I need to figure out how to register when it happens so that if it shows students can just write “NS” or “no solution”. Hopefully that makes sense. If not, let me know. Here is the code:

i=input

##################################################
#Randomly generated numbers

r=randomGenerator()

a=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
b=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
xfloat=numericValue("(-1)^${r.int(0,1)}*${r.int(0,8)}")
d=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
e=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
yfloat=numericValue("(-1)^${r.int(0,1)}*${r.int(0,8)}")

c1=numericValue("(${a}*${xfloat})+(${b}*${yfloat})")
c="${numericValue("\\operatorname{round}\\left(${c1},2\\right)")}"
h1=numericValue("(${d}*${xfloat})+(${e}*${yfloat})")
h="${numericValue("\\operatorname{round}\\left(${h1},2\\right)")}"

##################################################
#Creating x and y values for the coordinate comparisonn

x2="${numericValue("\\operatorname{round}\\left(${xfloat},2\\right)")}"
x1="${numericValue("\\operatorname{round}\\left(${xfloat},1\\right)")}"
x0="${numericValue("\\operatorname{round}\\left(${xfloat},0\\right)")}"

y2="${numericValue("\\operatorname{round}\\left(${yfloat},2\\right)")}"
y1="${numericValue("\\operatorname{round}\\left(${yfloat},1\\right)")}"
y0="${numericValue("\\operatorname{round}\\left(${yfloat},0\\right)")}"

##################################################
#Checking correctness

correct=    when  (   (parseOrderedPair(i.latex).x ="${x2}") or (parseOrderedPair(i.latex).x ="${x1}")
or (parseOrderedPair(i.latex).x ="${x0}") or (numericValue(parseOrderedPair(i.latex).x) =numericValue("${xfloat}")))

and   (   (parseOrderedPair(i.latex).y ="${y2}") or (parseOrderedPair(i.latex).y ="${y1}")
or (parseOrderedPair(i.latex).y ="${y0}") or (numericValue(parseOrderedPair(i.latex).y) =numericValue("${yfloat}")))

1 otherwise 0

co = when correct=1 "Correct, good work ${studentname.content}!" otherwise "Not there yet, keep working " ################################################## #Displayed content content: "Given the following two equations: ${a}x+${b}y=${c}
${d}x+${e}y=${h} Solve the system and find the solution.${co}"



No solution would be same slope but different y-intercepts. I’d use xyLine to check if the slopes are equal but the y-intercepts are not. (And maybe make variables for the equations’ latex for multiple uses.)

(I tried the example in the CL documentation to make sure xyLine takes standard form.)

Worked perfectly. Thank you as always!

Here is the updated with the slope and intercept check

i=input

##################################################
#Randomly generated numbers

r=randomGenerator()

a=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
b=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
xfloat=numericValue("(-1)^${r.int(0,1)}*${r.int(0,8)}")
d=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
e=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
yfloat=numericValue("(-1)^${r.int(0,1)}*${r.int(0,8)}")

f=numericValue("(-1)^${r.int(0,1)}*${r.int(3,10)}")
aa=numericValue("(${a}*${f})")
bb=numericValue("(${b}*${f})")
cc=numericValue("(${c}*${f})")

c1=numericValue("(${a}*${xfloat})+(${b}*${yfloat})")
c="${numericValue("\\operatorname{round}\\left(${c1},2\\right)")}"
h1=numericValue("(${d}*${xfloat})+(${e}*${yfloat})")
h="${numericValue("\\operatorname{round}\\left(${h1},2\\right)")}"

##################################################
#equations and their checks
eq1="${a}x+${b}y=${c}" eq2a="${d}x+${e}y=${h}"
eq2b="${aa}x+${bb}y=${cc}" eq2c="${aa}x+${bb}y=${c}"
eqwhat=r.int(1,6)
eq2=when eqwhat=1 "${eq2b}" when eqwhat=2 "${eq2c}" otherwise  "${eq2a}" eq1slope=xyLine(eq1).slope eq2slope=xyLine(eq2).slope eq1bVal=xyLine(eq1).yIntercept eq2bVal=xyLine(eq2).yIntercept ################################################## #Creating x and y values for the coordinate comparisonn x2="${numericValue("\\operatorname{round}\\left(${xfloat},2\\right)")}" x1="${numericValue("\\operatorname{round}\\left(${xfloat},1\\right)")}" x0="${numericValue("\\operatorname{round}\\left(${xfloat},0\\right)")}" y2="${numericValue("\\operatorname{round}\\left(${yfloat},2\\right)")}" y1="${numericValue("\\operatorname{round}\\left(${yfloat},1\\right)")}" y0="${numericValue("\\operatorname{round}\\left(${yfloat},0\\right)")}" ################################################## #Checking correctness correct= when ( (parseOrderedPair(i.latex).x ="${x2}")
or (parseOrderedPair(i.latex).x ="${x1}") or (parseOrderedPair(i.latex).x ="${x0}")
or (numericValue(parseOrderedPair(i.latex).x) =numericValue("${xfloat}"))) and ( (parseOrderedPair(i.latex).y ="${y2}")
or (parseOrderedPair(i.latex).y ="${y1}") or (parseOrderedPair(i.latex).y ="${y0}")
or (numericValue(parseOrderedPair(i.latex).y) =numericValue("${yfloat}"))) and (not(eq1slope=eq2slope)) 1 when eq1slope=eq2slope and (not(eq1bVal=eq2bVal)) and (i.latex="ns" or i.latex="NS" or i.latex="no\ solution" or i.latex="No\ solution" or i.latex="No\ Solution" or i.latex="nosolution" or i.latex="no\ soution\ " or i.latex="\ no\ solution") 1 when eq1slope=eq2slope and eq1bVal=eq2bVal and (i.latex="ims" or i.latex="IMS" or i.latex="Infinitely\ many\ solutions" or i.latex="Infinitely\ Many\ solutions" or i.latex="Infinitely\ Many\ Solutions" or i.latex="infinitely\ many\ solutions" or i.latex="infinitelymanysolutions" or i.latex="infinitely\ many\ solutions\ " or i.latex="\ infinitely\ many\ solutions" or i.latex="infinite\ solutions" ) 1 otherwise 0 co = when correct=1 "Correct, good work${studentname.content}!" otherwise "Not there yet, keep working "

##################################################
#Displayed content

content: "Given the following two equations:
${eq1} ${eq2}

Solve the system and find the solution.

\${co}"



Missed an L in one of your "no solution"s.