我有一个数字列表,我想将它们相加,然后将它们乘以一个常数。
addList := proc(a::list,b::integer)::integer;
local x,i,s;
description "add a list of numbers and multiply by a constant";
x:=b;
s:=0;
for i in a do
s:=s+a[i];
end do;
s:=s*x;
end proc;
sumList := addList([2, 2, 3], 2) 工作正常,但同时 sumList := addList([20, 20, 30], 2) 给出错误。有人可以指出错误吗?