 # Accepting only a decimal answer

If there a way to code a problem to accept on a decimal value as an answer? In other words to not also accept the equivalent fractional value.

You can use a pattern match to check if it’s in fraction form, and then use an errorMessage to remind the student to write the number in decimal form.

``````p = patterns

isFraction = p.fraction(p.integer, p. integer).matches (this.latex)

errorMessage: when isFraction "Please enter the number in decimal form." otherwise ""

``````

…or, for another strategy in your toolbox, you can utilize countNumberUsage:

``````check= this.numericValue=1.5 and countNumberUsage(this.latex)=1
``````

Just be aware, only checking numericValue will also accept 1.5x, so you may want to add in another evaluation:

``````... and simpleFunction(this.latex).evaluateAt(10)=1.5
``````

So how does this work if the current code is only:

disableEvaluation: true

correct: this.numericValue = 0.875

I didn’t look at your exact value. Change the 1.5 to 0.875.

The code in question takes the student input and turns it into a function, in my case, f(x)=1.5, so if you evaluate that function at any value you get 1.5. It’s just something to add on because desmos allows for “units” in a numericValue, so it treats 1.5x as though x is a unit.

Yes, I tried that and it still accepts 7/8 as correct. This lesson is about converting fractions to equivalent decimals. So, I clearly don’t want it to give credit for simply putting the fraction in for the answer.

Here is what I have:

disableEvaluation: true
check= this.numericValue=0.875 and countNumberUsage(this.latex)=0
correct: this.numericValue = 0.875

If you’re using @Daniel_Grubbs method, it should look like this.

``````disableEvaluation: true

check= this.numericValue=0.875 and countNumberUsage(this.latex)=1

correct: check

``````

Your previous code still only checked for a numeric value of 7/8, so it was going to accept either form. You also need the countNumberUsage to be set to 1 since only one number should be the input. If a student enters a fraction, that is considered 2 numbers.

If you use the pattern match and errorMessage method that was also suggested, you can just use numericValue to check because a student wouldn’t be able to submit a fraction.

1 Like

disableEvaluation: true
check= this.numericValue=0.875 and countNumberUsage(this.latex)=1
correct: check

You could also use the countNumberUsage instead of the pattern matching for the errorMessage for similar results to @cwinske’s solution (i.e. student can’t submit a fraction).

Ah. I understand now. Thank you very much!

I use a variable, check, so that I can reference it for other things if necessary, like student feedback or hiding components.