How can I have a student enter a fraction as an answer?

How can I have a student enter a fraction as an answer?

by Matt Lavery -
Number of replies: 16
Note: I have this sneaking suspicion that some other elementary or middle school math teacher has wrestled with a lot of these issues already, but they are all coming up for the first time to me. If you know someone who has used Moodle in this capacity already and may have some tips and tricks for this kind of use, please let me know. Thanks!

I need to provide the flexibility for my students to enter fractions as an answer, rather than simply provide multiple choice entries. I tried combining LaTeX with the cloze question type, and that really confused Moodle. I know I could pull it off if I could require multiple answer fields in a calculated question. Then, I could do something like this:

Enter your answers in the blanks below according to these labels: $$ whole \frac { numerator } { denominator } $$
Whole:
___________
Numerator:
___________
Denominator:
___________

Requiring them to enter the fraction has a lot more power, since I can check for common errors and oversights and provide specific feedback. If I give them multiple choice responses, I don't have nearly the flexibility for error analysis.

Ideas?

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

Average of ratings: -
In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by John Isner -
You could use Joseph Rezeau's Regular Expression Short Answer question type. You (teacher) will have to learn to write the regular expressions (which are used for the answers), and you'll need to explain to your students how you want them to input mixed numbers in a linear format (e.g., as a whole number followed by at least one space and then a proper fraction reduced to lowest terms). With regular expressions, you will be able to accept either mixed numbers or improper fractions as valid answers, and you'll be able to give some fairly good feedback (e.g., you can create regular expressions that detect when they haven't reduced to lowest terms). I don't think students should be writing LaTeX.

Regular expressions can be used for simple numbers (fractions, mixed numbers, decimal numbers, and probably extremely simple algebraic expressions). For anything more complicated, you'll need a decent computer algebra system.
In reply to John Isner

Re: How can I have a student enter a fraction as an answer?

by Matt Lavery -
Thank you, I'll look into such a thing. I had hoped for a bit more natural input method, but linear textual adaption could work.

By the way, I wasn't trying to set it up so that the students entered answers in LaTeX, I tried to set up a cloze question so that the answer blank appeared in the LaTeX output, instead of passing a static value. I should have realized right away that this wouldn't work, since LaTeX is basically an inline .gif maker. You certainly can't have an input control as part of a .gif, but that's ultimately what I'm after: Something that looks like a fraction, with a spot for them to enter their response in an intuitive way. Like this:
Example graphical fraction input
Someday, I'll code such a thing, but right now I'm balancing too much stuff. smile

Is RegEx my best approximation for this?

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by John Isner -
Hi Matt,
Ah, now I see what you're trying to do. It would be nice if you could do that with cloze. I haven't had much success getting cloze questions to lay out the way I want. If you figure out how to do it, let us know smile

Meanwhile, you could try Regex, but maybe it's not worth the extra effort if all you need is fractions and mixed numbers. Then plain short answer will be adequate, as Pierre suggests.
In reply to John Isner

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
Do you mean doing something like this in cloze questions?

{:SHORTANSWER...} {:SHORTANSWER...}

{:SHORTANSWER...}

I thought the problem was with the calculation rather than with the layout. thoughtful
Average of ratings:Useful (1)
In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by Pierre Pichet -
You could use simple short answer question type and you use as much answers as there are good responses if you allow simplified fractions i.e 1/2, 2/4, 4/8 or not.
You will need to create a set of questions to cover the range of values or difficulty level.
Here a simple example:
Express 7,75 as a fraction different from 7 75/100
Put a space between the whole number and the fraction i.e. 7 75/100

You put the following answers with a 100% grade value.
7 3/4
7 6/8
7 9/12
7 12/15
etc.

Pierre




In reply to Pierre Pichet

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
If I may add to and complicate a little bit this solution, in one of my experiments with cloze questions I got a similar effect while preserving a desired input layout by adding a block of html with input fields organized as desired and some javascript that copied the text from the input fields into the question's short-answer field. And so input was formatted in one way and the string that was actually matched against the predetermined answers was formatted in another.

Itamar
In reply to Itamar Tzadok

Re: How can I have a student enter a fraction as an answer?

by Matt Lavery -
What you described in both your posts is exactly what I'm after. It is more an issue of layout. If you have any code that demonstrates how to do this effectively, I would really appreciate it.

Thanks for your insight.

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
This layout simply uses a table (with border=0) but of course as a question it can only work with one correct answer.

{:SHORTANSWER...} {:SHORTANSWER...}

{:SHORTANSWER...}

As for the more flexible solution give me a sec to find it (or reinvent it, whichever comes first). I'll be right back. smile
In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
Okay I'm back. smile I couldn't find it so I created a quick simple example of the fraction exercise. You may notice in the images below that after submitting the answer (in a quiz) the values in the input fields are not preserved. They may be restored with just a little bit more work so if you wish to use this solution I can add this feature. By the way if you try it it won't work in the pop-up of the preview mode, only in a quiz.

In this example the values from the input fields are copied into the shortanswer field after the denominator loses focus, so the order of entering the values is important. Again, this is just a quick example and there is much more that can be done to make it more user-friendly.

Note that in the code the 'nnnnn' should be substituted with the name of the shortanswer field. So first you need to create the question like that and then open the question in preview mode, open the page html source and look up the name. Not very elegant but if it gets you what you need it is worth it.

Let me know if you need any other details. smile


fraction-front.jpg


fraction-back.jpg


fraction-result.jpg


Average of ratings:Useful (2)
In reply to Itamar Tzadok

Re: How can I have a student enter a fraction as an answer?

by Pierre Pichet -
One problem with this solution is that there seems that there are two ways to enter the value which is confusing for the student.

Pierre
In reply to Pierre Pichet

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
I agree but as I suggested this example is quite quick and dirty. The actual question can be laid out in such a way that most if not all confusion is eliminated. smile
In reply to Itamar Tzadok

Re: How can I have a student enter a fraction as an answer?

by Matt Lavery -
You have officially achieved rockstar status! That is exactly what I was after. I'll try to figure out a way to hide the official answer box from view, tweak the code so that it runs just prior to submission, and exploit the full spiffiness of RegEx to lend power to answer parsing. When I have a final working solution, I'll post it here (probably in the Fall, looking at my schedule).

Thanks to everyone for all your help!

- Matt Lavery
"You are responsible for everything you think, say, do, feel, and believe.
That is all you are responsible for, and you are the only one responsible for it."

In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
The official answer box can be hidden by placing it in a a div tag with style="visibility:hidden".

The image below shows that in a hidden kind of way. For each row there is an official answer box in the right most column which you cannot see because it is hidden so you'll have to take my word for it. wink

Notice the buttons which allow a student to validate an answer, display the correct answer and reset the fields. The buttons call javascript functions and pass relevant parameters to them. The functions do not reside in the question but rather in the "back-end" of a description question (which otherwise is empty) so that they can be called by multiple questions in the same quiz page without code duplication and conflicts.

This question was used for practice so the quiz assessment was not necessary in that case. Disabling the validation and display buttons can turn the question into formal assessment. Or disabling only the display button may allow a student to keep trying until the answer is figured out or time's up.

The image shows the question view after clicking 'Validate' which indicates a wrong answer in line 6.

dr-cmp-prc.jpg

In reply to Itamar Tzadok

Re: How can I have a student enter a fraction as an answer?

by Pierre Pichet -
I did not realize that the openness of the Cloze question allows inclusion of such modifications.
Using a description question to include javascript is quite an idea.
This remember me a work-around that I used on WebCT to synchronize numerical data between different calculated questions.

Pierre
In reply to Matt Lavery

Re: How can I have a student enter a fraction as an answer?

by Itamar Tzadok -
One more thing smile An alternative way to access the official answer box without tracking its name is by placing it in a known position relative to an identified html element in the question and navigating the DOM hierarchy.