我正在运行一个测试rowcol,基本上将行和列相乘以得出它是否等于原始的。我在纸上做了这个矩阵是如何完成的。但是当我运行它时,它总是说断言错误不相等。 我已经仔细检查了所有内容,以确保没有额外的缩进没有额外的数字或任何东西。
代码:
def test_rowcol_product_1( self ):
""" Row col product """
row = [4,5,6]
col = [3,7,11]
self.assertEqual( rowcol_product(row, col), 4*3 + 5*7 + 6*11 )
我收到错误:
self.assertEqual( rowcol_product(row, col), 4*3 + 5*7 + 6*11 )
AssertionError: None != 113
答案 0 :(得分:0)
我将在此处采取先发制人的猜测: rowcol_product 根本不会返回任何值。例如(使用非常简单的实现):
例如:
def rowcol_product(a, b):
prod = 0
for i in range(len(a)):
prod += a[i]*b[i]
Without a statement at the end to explicitly return the computed total,
return prod
... the default return from the function is **None**. Add the missing statement to the bottom of the function.