运行python列时出现错误

2024-04-18 20:33:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个测试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 )

收到错误:

^{pr2}$

Tags: 代码testselfdef错误矩阵数字col
1条回答
网友
1楼 · 发布于 2024-04-18 20:33:34

我在这里先发制人地猜测: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.

相关问题 更多 >