Distance between points (random generator)

I’m trying to randomly generate numbers for students to find the distance between points using the Pythagorean Theorem. Every variable will check correctly until I get to the final stage of taking the square root of g. Do you see a problem with my code?



c= numericValue("{y_2} - {y_1}")
d= numericValue("{x_2} - {x_1}")
e=numericValue("{c}^2") f=numericValue("{d}^2")

content:"Find the distance from ({x_1},{y_1}) to ({x_2},{y_2}).


result =
when input19.submitted and input19.latex=("\sqrt${g}") “:raised_hands:\n\n\Correct​:raised_hands:”
when input19.submitted “\n\n\Incorrect. Try again.”
otherwise “”

Latex matching isn’t the best and it’s hard to tell what you’re actual code is (since the forum reformats some things). If you use triple backticks for the first and last lines of your code in the forum it will show your intended code.

However, I’d guess the problem is in the sqrt g, which should be something like:


Also, not sure if you’re using c, d, e, and f to assess anything, but you could define g in one shot:

g= numericValue("(${y_2}-${y_1})^{2}+(${x_2}-${x_1})^{2}")
1 Like

Daniel beat me to it - although, @Daniel_Grubbs, do you know if it’s a new thing that the site shows that you are replying in real time?

I agree, the latex matching is not great. You could try something like this:

Also of note - make sure you enclose values to be squared in parantheses:

-3^{2}= -9
(-3)^{2} = 9

Instead of matching the latex strings, it can be easier to define functions and evaluate them at the same points to see if you get equivalent outputs.

   when simpleFunction(input19.latex).evaluateAt(1)=FnG.evaluateAt(1) “:raised_hands:\n\n\Correct​:raised_hands:”
   otherwise ""

Not new. I’ve seen it before. I saw you replying when I edited my comment as well.

1 Like

Yes, my square root was formatted incorrectly. Thank you!

1 Like

Thank you. This is very helpful.

1 Like

Cheryl, could you share your activity here? I’m trying to do the same thing. No sense in reinventing the wheel, right??