2017-03-02 70 views
-1

我想打一個程序圖中,兩個理想氣體,但殼推出這個錯誤:IDEAL GASSES TypeError:不能通過類型爲'float'的非整型來乘序列3.4.4?

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中使用Python 3.4.4。我想獲得一個依賴於P的P(P從0變到800)的圖形,列表T中的每個溫度對於每個摩爾體積的氖和Kripton列表Vn。 爲什麼我不能用P乘以和劃分列表的這些元素? 非常感謝。

+0

你應該輸入你的代碼,它說「在這裏輸入代碼」。 – user2357112

+0

對不起,我已經發布了代碼。 – Moneqz

回答

0

有點調試有很長的路要走。更改你的函數

def P1(P): #Función de P: 
    print(type(P), type(Vn[c]), type(T[c2])) 
    return (P*(Vn[c]))/(T[c2]) 

並運行它打印

<class> 'list' <class 'float'> <class 'float'>

你想多一個list有兩個floats,這顯然是行不通的。 P = list(range(0, 800)),所以你將需要使用一些索引。我不知道你想做什麼,但作爲一個例子,下面的函數對我來說運行良好:

def P1(P): #Función de P: 
    #   | just added an index here 
    return (P[0]*(Vn[c]))/(T[c2]) 
相關問題