简体   繁体   English

TypeError:“ NoneType”对象不可调用(初学者)Python

[英]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. 它告诉我第11行有一个AssertionError我是编程新手,不确定是否有帮助,代码应该给我第x行的第i个元素,因此对于row3(3)= row4(10)= 40时为9。

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 中的AssertionError Traceback(最近一次通话)

10 row3 = multiplicationtable(3) 10 row3 =乘法表(3)

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

AssertionError: Asse田:

You are getting AssertionError because row(i) function is not returning any value. 您正在获取AssertionError因为row(i)函数未返回任何值。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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