WeBWorKdocs

sq_webwork:


Home
Current UR
courses
Visitor
page
Intro to
WeBWorK
WeBWorK 2
Twiki
WW
Community
Grant Support
& awards
Discussion
group
Problem
library
Write/modify
problems
Create &
manage course
Tutorial on
running a course
HowTos
FAQ
WeBWorK2
FAQ
Software
Download
How to
Install WW server
Feedback
Site Map
Change
preferences
Change
password





Prev | Next | tutorial

This page is no longer being maintained. The new URL for this content is http://webwork.maa.org/wiki/SampleProblem1


Complete the sentence:

world!


WARNINGS
µ¦å{h­ To get this problem you would enter the following (without the line numbers). (The code has been simplified slightly for pedagogical purposes. )
1       DOCUMENT();
2       loadMacros(
3               PGbasicmacros.pl,
4               PGanswermacros.pl,
5               PGchoicemacros.pl
6       );
7
8       TEXT(beginproblem());
9
10      BEGIN_TEXT
11              Complete the sentence: $PAR
12              \{ ans_rule(20) \}  world!
13      END_TEXT
14      ANS( str_cmp( "Hello" ) );
15
16      ENDDOCUMENT();

1       DOCUMENT();
The subroutine DOCUMENT() must the first line of any pg problem. It does setup procedures and initializes much of the information that will be used later on by WeBWorK to create the problem.
3       loadMacros(
4               PGbasicmacros.pl,
5               PGanswermacros.pl,
6       );
The loadMacros() call loads the specified macro files so that any macros that have been defined within them will be readily available to the professor.

Mandatory modules:

Optional modules:

8       TEXT(beginproblem());
The TEXT command is essentially the print command of the pg language. Everything that is passed to it, concatenated, evaluated, and then printed out.
The beginproblem() method prints some of the opening information that should be printed for each problem, such as how points it is worth and, if the user has permission, the filename of the problem.
10      BEGIN_TEXT
11              Complete the sentence: $PAR
12              \{ ans_rule(20) \}  world!
13      END_TEXT
The BEGIN_TEXT/END_TEXT pair is a replacement for the older EV2 and EV3 tags.
14      ANS( str_cmp( "Hello" ) );
The ANS subroutine stores the answer evaluators used to evaluate the students answer by comparing the submitted answer to the one given by the instructor. How the answers are compared is determined by which answer evaluator is used (str_cmp("Hello") is one example) all of which are listed in PGanswermacros.pl.
16      ENDDOCUMENT();
The ENDDOCUMENT() finishes up the pg problem and makes sure everything closes out correctly. This must be the last line in your problem (at best anything after this will be ignored, at worst it will cause an error).

Final Notes:

Because we are writing a perl script, each statement must end in a semi-colon. Note however that many statements can be several lines long (such as loadMacros(), lines 2-5), these only require one semi-colon. All of the extra exterior links, buttons, forms, pictures, etc that are common to all problems are generated by the WeBWorK scripts and do not (and cannot) be created within the pg problem itself.



Prev | Next | tutorial

Last update: Monday, March 3, 2008 at 3:20:41 PM.

This site maintained using Manila and Frontier software.