我是OOP的新手,我正在尝试在下面编写一个简单的类,但我不断得到一个NameError
class rng(object):
_rand_nums = [6,3,2,1]
_p = [0.1,2,0.7,0.4]
if any(i >= 1 for i in _p):
_norm = sum(_p)
_p = [i/_norm for i in _p]
当我尝试运行时,我得到:
<ipython-input-116-097f599a4ce0> in <listcomp>(.0)
15 if any(i >= 1 for i in _p):
16 _norm = sum(_p)
---> 17 _p = [i/_norm for i in _p]
NameError: name '_norm' is not defined
我的代码出了什么问题?我以为我定义_norm
很好。