0
我的代码将接受来自用户界面的值,然后计算出密度,但是当我尝试调用我的函数“Properties”时,它告诉我Pressure2是未定义的。对不起,如果我的格式不好,这是我的第一篇文章。Python中的调用函数Spyder为UI
`def variables(self): #This Function gets the initial conditions from the UI
pressure1=self.ui.pressure1.value
pressure2=self.ui.pressure2.value
temp1=self.ui.temp1.value
temp2=self.ui.temp2.value
`
def properties(self): #This Function pulls values from array, when user picks the gas.
if self.ui.gas_2.findText('Oxygen'):
rc=elementsMap['Oxygen'][1]
gamma=elementsMap['Oxygen'][0]
elif self.ui.gas_2.findText('Helium'):
rc=elementsMap['Helium'][1]
gamma=elementsMap['Helium'][0]
elif self.ui.gas_2.findText('Hydrogen'):
rc=elementsMap['Hydrogen'][1]
gamma=elementsMap['Hydrogen'][0]
def instanous(self): # This function calculates the instanous density.
rho2=self.variables(pressure2)/(self.properties(rc)*self.variables(temp2))
NameError: name 'pressure2' is not defined
`
答案就在你的错误之上。 – Mai
错误发生在最后一行代码上。 “rho2”对不起,我没有说清楚。 –
这就是答案。你把压力2放在未定义的地方。除此之外,你的代码在范围方面没有意义。在继续之前,您应该考虑查看一些教程或MOOC。 – Mai