简体   繁体   中英

TypeError: 'NoneType' object is not callable (Beginner) Python

It tells me there is an AssertionError in line 11.I'm new to programming, not sure if this helps.The code is supposed to give me the i-th element of the x-th row, so for row3(3) = 9 for row4(10) = 40.

def multiplicationtable(x):

    def row(i):
        print (x * i)
    return row

row3 = multiplicationtable(3)

assert row3(3) == 9

AssertionError Traceback (most recent call last) in

10 row3 = multiplicationtable(3)

---> 11 assert row3(3) == 9

AssertionError:

You are getting AssertionError because row(i) function is not returning any value. It should be written in this way:

def multiplicationtable(x):

    def row(i):
        print (x * i)
        return x * i
    return row
row3 = multiplicationtable(3)

assert row3(3) == 9

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