/home/jaubrey/webwork//pg_TRUNK/macros/PGsequentialmacros.pl

From WeBWorK

Jump to: navigation


NAME

        PGsequentialmacros.pl 
        
Provides support for writing sequential problems, where certain parts
of the problem are hidden until earlier questions are answered correctly.

SYNPOSIS

        The basic sequential problem structure:
        DOCUMENT();          
        loadMacros(.....);   
        ## first segment ##                 
    BEGIN_TEXT
        The first question: Enter \(sin(0) = \) \{ans_rule\}.
    END_TEXT
        ANS(num_cmp(0));
        if (@incorrect_answers = get_incorrect_answers( ) ) {
          TEXT( "These answers are not correct  ", join(" ",@incorrect_answers),$BR); 
          foreach my $label (@incorrect_answers) {
              checkAnswer($label,debug=>1);
          }
    }
    if (all_answers_are_correct() ) {
              TEXT("$PAR Right! Now for the next part of the problem");
    } else {
             STOP_RENDERING();
    }
        ## second segment ##    
             ....
        if (@incorrect_answers = get_incorrect_answers( ) ) {
          TEXT( "These answers are not correct  ", join(" ",@incorrect_answers),$BR); 
          foreach my $label (@incorrect_answers) {
              checkAnswer($label,debug=>1);
          }
    }
    if (all_answers_are_correct() ) {
              TEXT("$PAR Right! Now for the next part of the problem");
    } else {
             STOP_RENDERING();
    }
    ## third segment ## 
        ENDDOCUMENT()        # must be the last statement in the problem

DESCRIPTION

listFormVariables

        listFormVariables();
        listVariables();

Lists all variables submitted in the problem form and all variables in the the Problem environment. This is used for debugging.

checkAnswer

        checkAnswer($label);

Checks the answer to the question labeled $label. The result is 1 if the answer is completely correct. 0 if the answer is wrong or partially wrong and undefined if that question has not yet been answered. (Specifically if no answer hash is produced when the answer is evaluated by the corresponding answer evaluator.)

listQueuedAnswers

        listQueuedAnswers();

Lists the labels of the answer blanks which have been printed so far. The return value is a string which can be printed. This is mainly used for debugging.

checkQueuedAnswers

        checkQueuedAnswers();

Returns a hash whose key/value pairs are the labels of the questions have been printed so far and the scores obtained by evaluating the answers to these questions.

all_answers_are_correct

        all_answers_are_correct();

Returns 1 if there is at least one answer and all of the questions printed so far have been answered correctly.

get_incorrect_answers

        get_incorrect_answers();

Returns a list of labels of questions which have been printed and have been answered incorrectly. This list does NOT include blank or undefined answers. It's possible for the returned list to be empty AND for all_answers_are_correct() to return false.