<p>很可能您的<code>arrTuple</code>不是一个数字数组,但某些项是一个数组。在</p>
<p>要进行检查,请通过添加一些检查来修改代码:</p>
<pre><code>@outputSchema("result")
def isReconciled(arrTuple):
# some checks
tmpl = "Item # {i} shall be a number (has value {itm} of type {tp})"
for i, num in enumerate(arrTuple):
msg = templ.format(i=i, itm=itm, tp=type(itm))
assert isinstance(arrTuple[0], (int, long, float)), msg
# end of checks
arrTemp = []
arrNew = []
string1 = ""
result = 0
## the first element of the Tuple should be the sum of remaining values
varGrandTot = arrTuple[0]
## create a new array with the remaining Tuple values
arrTemp = arrTuple[1:]
for item in arrTuple:
arrNew.append(item)
## sum the second to the nth values
varSum = sum(arrNew)
## if the first value in the tuple equals the sum of all remaining values
if varGrandTot = varSum then:
#reconciled to the penny
result = 1
else:
result = 0
return result
</code></pre>
<p>它很可能会对其中一个项抛出<code>AssertionFailed</code>异常。阅读
要学习断言消息,哪一项是制造麻烦的。在</p>
<p>不管怎样,如果第一个数字等于数组其余部分的和,则返回0或1
也可以:</p>
^{pr2}$
<p>在这种情况下,你会很高兴得到<code>True</code>而不是1,而{<cd4>}而不是0:</p>
^{3}$