Checking Significant Places

I’m working on an activity that was previously handled in paper form. One of the questions asked requires an answer to be given to “three significant places”. Is there a neat general way to handle error checking for this type of numeric input?

The fact that nobody answered is a good indication that there is no easy way to do this. I would just note that the round function has an optional second argument that deals with precision so round(1.41422,3)=1.414. You can use this to check whether a student answer rounds to a correct value. However, it would be trickier to require a student to enter “6.200” instead of “6.2” for their answer. In that case, you might need to compare the LaTeX strings.

1 Like

Thanks Serge, I was just making sure there wasn’t a general solution that I’d missed. A LaTeX comparison is fine for the activity I’m working on.

There’s slightly better method than an exact latex check shared here if you’re interested.

2 Likes

Thanks Jay, I’ll use that suggestion!

You could try this borrowed from https://www.codegrepper.com/code-examples/python/how+to+round+to+3+significant+figures+in+python

round(Number, SigFigs - 1 -round(floor(log10(|Number|))))

Here’s an example in the Desmos Calculator
https://www.desmos.com/calculator/ardrybomi2

1 Like

That only controls the number of significant digits, but does not allow for checking 6.00!=6 for example.

Thanks David, I don’t need that for my particular case where the number and its decimal and significant places are known. It does, however, seem like part of the general solution covering cases where the number of decimal places is determined dynamically. I think Jay’s code could be generalised to match.

1 Like

Thanks @David_BUSH. Just working on a case where significant places was needed and your code worked perfectly!

1 Like