嘿伙计们,我完全迷失在这个python作业问题上的问题是定义一个函数compute_gas_volume,它返回给定参数压力,温度和摩尔数的气体体积。使用气体方程式PV = nRT,其中P是以帕斯卡为单位的压力,V是以立方米为单位的体积,n是摩尔数,R是气体常数8.3144621(J /(mol * K)),T是以开尔文为单位的温度
首发代码是
gas_const = 8.3144621
def compute_gas_volume((gas_pressure,,gas_temperature,gas_moles):
gas_pressure = 100.0
gas_moles = 1.0
gas_temperature = 273.0
gas_volume = 0.0
gas_volume = compute_gas_volume(gas_pressure, gas_temperature, gas_moles)
print('Gas volume:', gas_volume, 'm^3')
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:1)
由于法则是PV = nRT,体积可以简单地计算为V = nRT / P,因此:
GAS_CONST = 8.3144621
def compute_gas_volume(gas_pressure, gas_temperature, gas_moles):
return gas_moles * GAS_CONST * gas_temperature / gas_pressure
答案 1 :(得分:0)
将其重新排列为等于V:
private static readonly Random Rnd = new Random();
private static void Main()
{
// Initialize all moves to false
bool[] allMoves = new bool[64];
for (int i = 0; i < allMoves.Length; i++) allMoves[i] = false;
// Pretend a move was made and set some to true
allMoves[0] = true;
allMoves[3] = true;
allMoves[5] = true;
// Get ALL indexes of 'false' items (currently everything except 0, 3, and 5)
var validIndexes = GetIndexesOfFalseItems(allMoves).ToList();
// Choose a random item from that list
var randomValidIndex = validIndexes[Rnd.Next(validIndexes.Count)];
// Now we get our next move from our main list at that index
var nextMove = allMoves[randomValidIndex];
// Rest if game code...
}