【发布时间】:2016-07-01 00:39:04
【问题描述】:
这不适用于任何项目或任何东西,只是在搞乱。 (在 python shell 中执行此操作)
import random
def rand1():
random.gauss(0, 0.1) * 0.3 + random.gauss(0, 3) * 0.7
rand1() + 1
它想出了
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
为什么rand1() 在数学运算中不起作用?
即使我将它存储在像rand2 = rand1() 这样的变量中,它仍然会出现相同的消息。有没有办法将它存储为浮点数而不是 NoneType?
【问题讨论】:
-
你没有从你的函数中返回任何东西,所以它返回
None。 -
你需要返回你的结果
-
请解释一下,从我的函数中返回一些东西是什么意思?
-
@Cogswellx:看我的回答。