Hello! I have an activity where I want students to input 2 equations in standard form and have the coding indicate correctness for multiple formats of the same form. The two equations are x + y = 28 and 4x + 6y = 144. I want the coding to mark the answers as correct if they switch the variables such as y + x = 28 or 6y + 4x = 144, and also mark correct if they lead with the constant instead such as 28 = x + y, etc. Here’s what I have so far: Standard Form
Any help is appreciated! Thank you.
Pretty close! For the first input, your pattern requires a number. So for line 6 you can adjust your pattern and make it optional. The sum pattern already allows for any order, but if you ever desire it you can add .strictOrder
to modify it.
lhs = p.anyOf(p.sum(p.product(p.optional(p.number),(x)), p.product(p.optional(p.number),y)))
For allowing the reverse equation, just add a check for the rhs to you lhsmatch:
lhsmatch = lhs.matches(expr.lhs) or lhs.matches(expr.rhs)
The other reason it’s not working is evaluating your difference function with those ordered pairs do not equal 0 because they’re not solutions to the equation.
Are you familiar with xyLine()?
If you use that instead of simpleFunction it will save a lot of grief. It will take a line in any format and then you can just check its slope and intercept values. This will also let you deal with vertical lines.
Let me know if you’d like an example.
1 Like
Thank you, this worked perfectly!
Thanks for the reminder about xyLine()!