Here is my code (you can see my several attempts at defining $h and 'forcing' the code to evaluate it at integers):
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGML.pl",
"MathObjects.pl",
"parserPopUp.pl", # For multiple choice questions with a drop down menu
"PGcourse.pl"
);
TEXT(beginproblem());
Context("Numeric");
Context()->variables->add( n => 'Real' ); # To add a new variable
$a = random(2,5,1);
$f = Formula("($a**n)/((n+1)!)");
$g = Formula("($a**(n+1))/((n+2)!)");
# $h = $g / $f;
# $h->{test_points} = [[1],[2],[3],[4],[5]];
# $h = Formula("$g / $f")->with(test_points => [[2],[3],[4],[5],[6]]);
$h = Formula("(($a**(n+1))/((n+2)!)) / (($a**n)/((n+1)!))")->with(test_points => [[2],[3],[4],[5],[6]]);
$ans = 0;
$popup = PopUp(["?", "Convergent", "Divergent", "Unknown"], "Convergent");
BEGIN_PGML
Consider the series [`` \sum_{n=1}^{\infty} \frac{[$a]^n}{(n+1)!} ``].
The limit for the Ratio Test is
[`` \lim_{n \rightarrow \infty} ``] [______________]{$h} [` = `] [_____]{$ans} (insert both the quantity to evaluate and the answer for the limit).
The series is [________________]{$popup} (select "unknown" if the ratio test is inconclusive).
END_PGML
$showHint = 3;
BEGIN_PGML_HINT
Note that, if [`` a_n = \frac{[$a]^n}{(n+1)!} ``], then [`` a_{n+1} = \frac{[$a]^{n+1}}{(n+2)!} ``].
END_PGML_HINT
$showHint = 6;
BEGIN_PGML_HINT
Note that [` (n+2)! = (n+2) \cdot (n+1)! `]
END_PGML_HINT
BEGIN_PGML_SOLUTION
The limit for the Ratio Test is
[`` \lim_{n \rightarrow \infty} \frac{ \displaystyle \frac{[$a]^{n+1}}{(n+2)!} }{ \displaystyle \frac{[$a]^n}{(n+1)!} } = \lim_{n \rightarrow \infty} \frac{[$a]^{n+1}}{(n+2)!} \cdot \frac{(n+1)!}{[$a]^n} = \lim_{n \rightarrow \infty} \frac{[$a]^{n+1}}{[$a]^n} \cdot \frac{(n+1)!}{(n+2)!} = \lim_{n \rightarrow \infty} \frac{[$a]\cdot[$a]^n}{[$a]^n} \cdot \frac{(n+1)!}{(n+2)(n+1)!} = \lim_{n \rightarrow \infty} [$a] \cdot \frac1{n+2} = 0 < 1 ``].
Therefore, the series [`` \sum_{n=1}^{\infty} \frac{[$a]^n}{(n+1)!} ``] is convergent by the Ratio Test.
END_PGML_SOLUTION
ENDDOCUMENT;