我想制作一个程序来绘制两种理想气体的图形,但炮弹发射时出现了以下错误:
line 10, in P1
return (P*(Vn[c]))/(T[c2])
TypeError: can't multiply sequence by non-int of type 'float'
这是我的节目:
#Prueba de gráfica de gas ideal con volumen molar
import numpy as np
from matplotlib import pyplot as plt
#Sea Vn=miu/densidad... VnNeón=16.82 ml/mol, VnCriptón=32.23 ml/mol
Vn=[16.82,32.23]
T=[0.01,60,137,258]
c=0 #contador del material
c2=0 #contador temperatura
def P1(P): #Función de P:
return (P*(Vn[c]))/(T[c2])
P= list(range(0,800))
while c<=1:
while c2<=3:
print(P1(P),Vn[c],T[c2])
c2=c2+1
c=c+1
我能做什么? 我在windows 10中使用Python3.4.4。我想得到一个P1的图表,它依赖于P(P从0到800),对于列表T中的每个温度,对于列表Vn中的每个氖和克里普顿摩尔体积。 为什么我不能用P来乘和除列表中的元素? 非常感谢你
稍微调试一下会有很大帮助。将函数更改为
运行它会打印
您试图将一个
list
与两个floats
相乘,这显然不起作用P = list(range(0, 800))
,因此您需要使用一些索引。我不确定您想做什么,但作为一个例子,以下函数对我来说运行良好:相关问题 更多 >
编程相关推荐