WeBWorK Problems

answer checking a list of one list

Re: answer checking a list of one list

by Davide Cervone -
Number of replies: 0

List-handling is a bit delicate, and there are some ambiguities. In particular, lists consisting of a single item are troublesome, mostly because the student can't really enter one. For example, the string "(a)" is not a list, in general, it is just the value "a". Perhaps and better example is "(5-2)" which is just the value 3 not a list containing the value 3. Similarly, "((1,2))" is just parentheses around the list (1,2) (or the point (1,2), depending on the context). (The problem is really the overuse of parentheses for both lists and grouping). So a student can't really make the distinction between a singleton list and the element that makes it up. While you as the program author can use List(List(...)) to make the meaning clear, the student entering an answer can't.

There is also a problem based on the fact that lists sometimes want parentheses (as in "(1,2)") and other times don't (as in "(1,2),(3,4)"). Most of the time, lists are used for students to enter without parentheses, so List(1,2) is usually entered by students as "1,2" with no parentheses. Thus the List() function usually produces lists without parentheses. So your List(List("a","b")) produces a list with a list with no parentheses. That's why "a,b" is the correct answer, while "(a,b)" is not. (The list must match not just in the elements, but in the parentheses, too, in general, though there are flags you can set to change that.)

The solution to your problem is to use $ans = List("(a,b)") (giving the answer in the form that the student will enter it). This makes a list were the parentheses are required, and it will match "(a,b)" but not "a,b".