Difference between revisions of "AlignedChoice"
Jump to navigation
Jump to search
Line 55:  Line 55:  
$f6 = Formula("sin(2pi)"); 
$f6 = Formula("sin(2pi)"); 

−  Parser::Context::Functions::Disable('All'); 

+  Context()>functions>disable("All"); 

−  Parser::Context::Functions::Enable('sqrt'); 

+  Context()>functions>enable("sqrt"); 

−  
Context()>texStrings; 
Context()>texStrings; 
Revision as of 15:51, 18 February 2010
Aligned Answer Blanks
This PG code shows how to align answer blanks and restrict the type of student answer allowed.
PG problem file  Explanation 

DOCUMENT(); loadMacros( "PGstandard.pl", "PGunion.pl", "MathObjects.pl", "alignedChoice.pl", ); TEXT(beginproblem()); 
Initialization:
We need to include the macro file 
Context("Numeric"); $f1 = Formula("sin(pi/6)"); $f2 = Formula("sin(pi/4)"); $f3 = Formula("sin(pi/3)"); $f4 = Formula("sin(pi/2)"); $f5 = Formula("sin(pi)"); $f6 = Formula("sin(2pi)"); Context()>functions>disable("All"); Context()>functions>enable("sqrt"); Context()>texStrings; $al = new_aligned_list(ans_rule_len=>10, numbered=>1, tex_spacing=>"3pt"); $al>qa( "\($f1\)", Real($f1>eval)>cmp, "\($f2\)", Real($f2>eval)>cmp, "\($f3\)", Real($f3>eval)>cmp, "\($f4\)", Real($f4>eval)>cmp, "\($f5\)", Real($f5>eval)>cmp, "\($f6\)", Real($f6>eval)>cmp, ); Context()>normalStrings; 
Setup: We disable all functions, and then enable square root. The options for aligned list are vertical alignment, horizontal alignment, cellspacing, tex spacing (which must include units of measure, such as "3pt"), whether or not the list is numbered, whether there is a column of equals signs, and the length of each answer rule. The defaults and other options are given below.

BEGIN_TEXT Find the sine of each of the following angles. $PAR \{ $al>print_q() \} $PAR Remark: Your answer cannot contain trigonometric functions. It must be an arithmetic expression or number. END_TEXT 
Main Text: It's a good idea to explain to students that the type of answers allowed are restricted. 
$showPartialCorrectAnswers = 1; ANS( $al>correct_ans ); ENDDOCUMENT(); 
Answer Evaluation: As expected. 