To obtain the problem:
Complete the sentence:
world!
you would type the following:
loadMacros(PG.pl,
PGbasicmacros.pl,
PGchoicemacros.pl,
PGanswermacros.pl
);
DOCUMENT();
TEXT( "Complete the sentence: $PAR", ANS_RULE(1,20), "world!" );
ANS( str_cmp( "Hello" ) );
ENDDOCUMENT();
To test or modify this problem click here.
Comments:
The basic structure of a problem written in the pg language is very simple:
- The
loadMacros(...)
statement loads the files containing the macros which implement the pg language.
- The subroutine
DOCUMENT()
does setup procedures.
TEXT(...,...,...,)
concatenates its inputs and prints them. This is the text of the problem.
ANS(...)
This specifies how to check whether the answer is correct.
- The subroutine
ENDDOCUMENT()
finishes the problem.
The subroutine ANS_RULE(1,20)
creates space for the first answer, 20 characters long.
The variable $PAR
indicates a new paragraph -- <P> for HTML or par for TeX output
The subroutine str_cmp("Hello")
checks that the answer matches "Hello". The match is case-insensitive.
Because we are writing a Perl script each statement must end in a semi-colon.
The WeBWorK scripts add the necessary HTML code for the
"Submit Answer" button; and a header and footer which
place the output inside a FORM.