当我尝试在另一个函数中使用函数时
错误
TypeError:* 不支持的操作数类型:’float’ 和 ‘NoneType’
# Function to calculate 2D circularity ratio def defineCircularRatio(perim2D, area2D): circularity_ratio = (4*math.pi*area2D)/(perim2D**2) return circularity_ratio print "The 2D circul_ratio is:", circularity_ratio
周长和面积 - 由其他函数计算。
原文由 asdqwery 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是给出错误的行:
Now since it has
float
beforeNoneType
in the error andmath.pi
is a float itself, this means thatperim2D
was never defined or is等于零,因此NoneType
。perim2D
声明为整数或浮点数以防止错误。例如:The above code
variable
asperim2D
, which solves the problem asperim2D
is no longer equal toNone
but to 2.other_variable
曾经被分配给area2D
。