我是 Python 新手,我正在尝试创建一个函数,该函数根据用户输入创建具有不同材料参数的列表,如下面的代码所示。
def material():
layers = int(raw_input("State the number of material layers in the wall (0 for default material): "))
rho = [] # Density [kg/m3]
c = [] # Heat capacity [J/(kg K)]
k = [] # Heat conductivity [W/(m K)]
#a = [] # Thermal diffusivity [m2/s]
d = [] # Thickness of material [m]
# Saveing material properties
if layers == 0:
rho.append(2300)
c.append(900)
k.append(1.6)
d.append(3.2)
layers = 1
else:
for i in range(layers):
print "\n" "Define thermal properties for material", i+1,"(starting from left)"
rho.append(float(raw_input("Density [kg/m3]: ")))
c.append(float(raw_input("Heat capacity [J/(kg K)]: ")))
k.append(float(raw_input("Heat conductivity [W/(m K)]: ")))
d.append(float(raw_input("Thickness [m]: ")))
return ???
我应该如何返回rho、c、k、d和图层,以便我能够例如打印 - 或使用值 - 例如d列表中的第二项?
print d[1]