单个数字总和;“缺失数字视为零”

单个数字总和;“缺失数字视为零”

我正在尝试创建一个工作表,让学生练习加个位数。

由于 10 或更大的总和更难,我希望相应的问题更频繁地出现。

但这无法编译。我不确定为什么。

这是我缺少分号或类似符号的情况之一吗?

\documentclass{article}

\usepackage{ifthen}
\usepackage{pgf}
\usepackage{pgffor}
 \pgfmathsetseed{\number\pdfrandomseed}


\newcommand{\MixedSum}
{%
%These guarantee sum>=10
\pgfmathsetmacro{\A}{int(random(1,9))}
\pgfmathsetmacro{\D}{int(10-\A)}
\pgfmathsetmacro{\B}{int(random(\D,9))}
\pgfmathsetmacro{\C}{int(\A+\B)}
%
%These are any two single digits added
\pgfmathsetmacro{\X}{int(random(0,9))}
\pgfmathsetmacro{\Y}{int(random(0,9))}
\pgfmathsetmacro{\Z}{int(\X+\Y)}
%
\pgfmathsetmacro{\r}{int(rand(1,2))}
\ifcase\r\relax%
 \or \(\A+\B=\C\)
 \or \(\X+\Y=\Z\)
\fi
}

\begin{document}

\MixedSum

\MixedSum

\MixedSum

\MixedSum

\end{document}

答案1

random沒有rand和缺失%

\documentclass{article}
\errorcontextlines100
\usepackage{ifthen}
\usepackage{pgf}
\usepackage{pgffor}
 \pgfmathsetseed{\number\pdfrandomseed}


\newcommand{\MixedSum}
{%
%These guarantee sum>=10
\pgfmathsetmacro{\A}{int(random(1,9))}%
\pgfmathsetmacro{\D}{int(10-\A)}%
\pgfmathsetmacro{\B}{int(random(\D,9))}%
\pgfmathsetmacro{\C}{int(\A+\B)}%
%
%These are any two single digits added
\pgfmathsetmacro{\X}{int(random(0,9))}%
\pgfmathsetmacro{\Y}{int(random(0,9))}%
\pgfmathsetmacro{\Z}{int(\X+\Y)}%
%
\pgfmathsetmacro{\r}{int(random(1,2))}%
\ifcase\r\relax
 \or \(\A+\B=\C\)%
 \or \(\X+\Y=\Z\)%
\fi
}

\begin{document}

\MixedSum

\MixedSum

\MixedSum

\MixedSum

\end{document}

答案2

您的设置\r不正确,因为它使用了

\pgfmathsetmacro{\r}{int(rand(1,2))}

rand返回介于 -1 和 1 之间的值(均匀分布),因此rand(1,2)没有意义。你可能想要

在此处输入图片描述

\documentclass{article}

\usepackage{pgf}
 \pgfmathsetseed{\number\pdfrandomseed}

\newcommand{\MixedSum}
  {%
  %These guarantee sum>=10
  \pgfmathsetmacro{\A}{int(random(1,9))}%
  \pgfmathsetmacro{\D}{int(10-\A)}%
  \pgfmathsetmacro{\B}{int(random(\D,9))}%
  \pgfmathsetmacro{\C}{int(\A+\B)}%
  %
  %These are any two single digits added
  \pgfmathsetmacro{\X}{int(random(0,9))}%
  \pgfmathsetmacro{\Y}{int(random(0,9))}%
  \pgfmathsetmacro{\Z}{int(\X+\Y)}%
  %
  \pgfmathsetmacro{\r}{int(random(1,2))}%
  \ifcase\r
    \or \(\A+\B=\C\)
    \or \(\X+\Y=\Z\)
  \fi
  }

\begin{document}

\MixedSum

\MixedSum

\MixedSum

\MixedSum

\end{document}

相关内容