Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 如何在WebWork中使用循环创建显示表?(PG)_Loops_Perl - Fatal编程技术网

Loops 如何在WebWork中使用循环创建显示表?(PG)

Loops 如何在WebWork中使用循环创建显示表?(PG),loops,perl,Loops,Perl,大约一周前,我开始学习Perl,现在我正在网络工作中制造问题,帮助学生练习衍生技能。我想以尽可能少的劳动密集型方式打印一份问题表和相应的答案框,因为这些问题将大量生产 到目前为止,我一直在手动输入所需的代码,并需要大量的复制粘贴。当前结构的示例如下所示: @questions=( "x(x+1)", "x^2(1-x)", "(x+2)(3x-4)", "(x-\sqrt{x})(x+\sqrt{x})", &quo

大约一周前,我开始学习Perl,现在我正在网络工作中制造问题,帮助学生练习衍生技能。我想以尽可能少的劳动密集型方式打印一份问题表和相应的答案框,因为这些问题将大量生产

到目前为止,我一直在手动输入所需的代码,并需要大量的复制粘贴。当前结构的示例如下所示:

@questions=(
"x(x+1)",
"x^2(1-x)",
"(x+2)(3x-4)",
"(x-\sqrt{x})(x+\sqrt{x})",
"(x^3-\frac{x^2}{3}-1)(2-x)",
"(x^3-2x)(x^{-2}+\frac{1}{x^4})",
"\frac{x-\sqrt{2x}}{x^2}"
);

BEGIN_TEXT
$BR $BR
Find the derivatives. 
$PAR
END_TEXT

@header=(" f(x) "," f '(x) ");
@header = map {EV3($_) } @header;

TEXT(
begintable(1+scalar(@header)), 
    row(@header),
    row("\[\qquad{$questions[0]}\qquad\]",ans_rule(10)),
    row("\[\qquad{$questions[1]}\qquad\]",ans_rule(10)),
    row("\[\qquad{$questions[2]}\qquad\]",ans_rule(10)),
    row("\[\qquad{$questions[3]}\qquad\]",ans_rule(10)),
    row("\[\qquad{$questions[4]}\qquad\]",ans_rule(10)),
    row("\[\qquad{$questions[5]}\qquad\]",ans_rule(10)),
    row("\[\qquad{$questions[6]}\qquad\]",ans_rule(10)),
endtable() 
);
我想使用一个循环来让事情变得更干净,并且当集合中的问题数量发生变化时,不再需要更新行。这是我迄今为止尝试过的,但是WebWorK不希望在不抛出语法错误的情况下接受它,这让我相信我无法在表构造中执行循环

@questions=(
"x(x+1)",
"x^2(1-x)",
"(x+2)(3x-4)",
"(x-\sqrt{x})(x+\sqrt{x})",
"(x^3-\frac{x^2}{3}-1)(2-x)",
"(x^3-2x)(x^{-2}+\frac{1}{x^4})",
"\frac{x-\sqrt{2x}}{x^2}"
);

BEGIN_TEXT
$BR $BR
Find the derivatives. 
$PAR
END_TEXT

@header=(" f(x) "," f '(x) ");
@header = map {EV3($_) } @header;

TEXT(
begintable(1+scalar(@header)), 
    row(@header),
    for($i = 0; $i <= $#questions; $i++) {
    row("\[\qquad{$questions[$i]}\qquad\]",ans_rule(10)),
    }
endtable() 
);
错误消息:

ERRORS from evaluating PG file: 
 syntax error at (eval 28451) line 74, at EOF
syntax error at (eval 28451) line 76, near ") 
)"
TEXT()
函数需要一个值列表。for循环将显示在此参数列表中,因为它的计算结果不是一个值列表,因此它没有任何用处。 在调用
TEXT()
函数之前创建值:

@questions=(
"x(x+1)",
"x^2(1-x)",
"(x+2)(3x-4)",
"(x-\sqrt{x})(x+\sqrt{x})",
"(x^3-\frac{x^2}{3}-1)(2-x)",
"(x^3-2x)(x^{-2}+\frac{1}{x^4})",
"\frac{x-\sqrt{2x}}{x^2}");

@formatted = map { row("\[\qquad{$_}\qquad\]",ans_rule(10))} @questions;

BEGIN_TEXT
$BR $BR
Find the derivatives. 
$PAR
END_TEXT

@header=(" f(x) "," f '(x) ");
@header = map {EV3($_) } @header;

TEXT(
begintable(1+scalar(@header)), 
    row(@header),
    @formatted,
endtable() 
);

在浏览了一下WebWorK之后,它似乎使用了一种基于Perl的语言,称为PG。尝试将其替换为:
map{row(\[\qquad{$\u}\ qquad\]”,ansu规则(10))}@questions
@clamp我尝试插入您提供的代码段,虽然它对我来说应该可以工作,但在执行时会抛出错误。我将编辑原始问题并附加结果。我发布了一个答案(测试日期)
@questions=(
"x(x+1)",
"x^2(1-x)",
"(x+2)(3x-4)",
"(x-\sqrt{x})(x+\sqrt{x})",
"(x^3-\frac{x^2}{3}-1)(2-x)",
"(x^3-2x)(x^{-2}+\frac{1}{x^4})",
"\frac{x-\sqrt{2x}}{x^2}");

@formatted = map { row("\[\qquad{$_}\qquad\]",ans_rule(10))} @questions;

BEGIN_TEXT
$BR $BR
Find the derivatives. 
$PAR
END_TEXT

@header=(" f(x) "," f '(x) ");
@header = map {EV3($_) } @header;

TEXT(
begintable(1+scalar(@header)), 
    row(@header),
    @formatted,
endtable() 
);