我想写一个加热器功能,但我有一些困难。我对Python相当陌生。错误与elif和if语句
我想我的加热器运行15000秒,但前120秒(包括120),我希望它遵循线性路径T = 0.0804 * t + 16.081
,然后120秒后,我希望它保持恒定的剩余的其余部分根据线性方程得出最终温度下的时间。
我写的代码是低于我得到的错误与
import math, numpy as np
from random import *
a = 0.0804
time = range(15001)
for time in xrange(15001):
if 0 < = time < = 120:
Temp = a * np.array(time) + 18.3
elif time > 121:
Temp = Temp[120]
错误:
TypeError
Traceback (most recent call last)
/Library/Python/2.7/site-packages/ipython-1.0.0_dev-py2.7.egg/IPython/utils/py3compat.pyc in execfile(fname, *where)
202 else:
203 filename = fname
--> 204 builtin.execfile(filename, *where)
/Users/mariepears/Desktop/heaterfunction.py in <module>
() 16 print T
17 elif t>121:
---> 18 T=T[120]
TypeError: 'int' object is not subscriptable`
好吧,有什么错误? (我甚至不知道该怎么说你的变量名) – Doorknob
请编辑它到问题中,以便它实际上是可读的。 – Doorknob
@MariePears如果您将其编辑到您的问题中,它肯定会提高可读性。 – glglgl