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 | pglanguage

'Hello World' program

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:
  1. The loadMacros(...) statement loads the files containing the macros which implement the pg language.
  2. The subroutine DOCUMENT() does setup procedures.
  3. TEXT(...,...,...,) concatenates its inputs and prints them. This is the text of the problem.
  4. ANS(...) This specifies how to check whether the answer is correct.
  5. 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.

<| Post or View Comments |>


Prev | Next | pglanguage

Last update: Wednesday, January 10, 2007 at 9:45:45 PM.
This site maintained using Manila and Frontier software.