【发布时间】:2019-09-20 10:21:07
【问题描述】:
我在使用列表时遇到了一些问题。我只想要一个非常简单的东西,只需从函数中的列表中获取一个数字,然后将这个数字乘以另一个主要的数字。实际上它有效,我的意思是从列表中取出的数字是正确的,但是当我将它乘以主要的数字时,python 例外说我不能将“float”与“Nonetype”相乘。所以基本上Python说我在列表中的实际浮点数是notype。有什么建议吗?
对不起,我是新来的。不知道把代码放在哪里,所以我把它放在这里:
def findTime(time):
day = 86400
seconds = time % day
f = [0.005, 0.03, 0.08, 0.15, 0.3, 0.7, 1, 0.8, 0.65, 0.5, 0.4, 0.3]
perc = np.array(f, float)
step = 2*60*60 # 2hours step
phase_di_prima = -1
i = 0
for phase in range(0,day, step):
#print("phase", phase)
i = 0
if seconds<phase and seconds>phase_di_prima:
percentuale = perc[i]
print("for arrival = "+ str(seconds)+ " perc = "+ str(percentuale))
return percentuale.astype(float)
phase_di_prima = phase
i += 1
main
time_arrival = env.now + time_shift
while True:
perc = findTime(time_arrival)
arrival_rate *= perc <----- error here
TypeError:*= 不支持的操作数类型:“float”和“NoneType”
【问题讨论】:
-
python 2 还是 3??
-
您的变量仅在函数中定义。 Main 有点乱了。
-
假设 1 需要在 "f" 中为 1.0?