简体   繁体   中英

Assertion error on python while running rowcol test

I am running a test rowcol basically multiplying the row and column to get the out come to see if it is equal to the original. I did this on paper how matrices are done. But when I run it it always says the the assertion error is not equal. I've double checked everything to make sure no extra indention no extra numbers or anything.

code:

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 )

error I receive:

self.assertEqual( rowcol_product(row, col), 4*3 + 5*7 + 6*11 )
AssertionError: None != 113

I'm going to take a pre-emptive guess here: rowcol_product doesn't return a value at all. For instance (using a very simple implementation):

For instance:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM