我正在尝试计算极限试剂,但是一旦到达该行的那部分计算,我就会收到此错误:
gramOxygenAA = (moleOxygen * (2/1)) * ((12.011*2) + (1.008*4) + (15.9994 * 2))
这是我的代码:
# Function that determines moles of oxygen input
def moleOxygen (gramOxygen):
moleOxygen = gramOxygen / (15.9994 * 2)
print ("Moles of oxygen available:", format(moleOxygen,'.2f'))
return (moleOxygen)
# Function that determines moles of acetaldehyde input
def moleAcetaldehyde (gramAcetaldehyde):
moleAcetaldehyde = gramAcetaldehyde / ((12.011*2) + (1.008*4) + 15.999)
print ("Moles of acetaldehyde available:", format(moleAcetaldehyde,'.2f'))
return moleAcetaldehyde
# Function that determines grams of Acetic Acid produced from available oxygen
def gramOxygenAA (moleOxygen):
gramOxygenAA = (moleOxygen * (2/1)) * ((12.011*2) + (1.008*4) + (15.9994 * 2))
print ("Grams of Acetic Acid that can be produced from available oxygen is", format(gramOxygenAA,'.2f'))
return gramOxygenAA
# Function that determines grams of Acetic Acid produced from available acetaldehyde
def gramAcetaldehydeAA ():
gramAcetaldehydeAA = (moleAcetaldehyde / (2/2)) *((12.011*2) + (1.008*4) + (15.9994 * 2))
print ("Grams of Acetic Acid that can be produced from available acetaldehyde is", format(gramAcetaldehydeAA, '.2f'))
return gramAcetaldehydeAA
# Function that determines the Limiting Reagent
def limitingReagent():
if gramOxygenAA < gramAcetaldehydeAA:
smaller = gramOxygenAA
print ("Oxygen is the limiting reagent")
else:
smaller = gramAcetaldehydeAA
print ("Acetaldehyde is the limiting reagent")
return smaller
def main ():
gramOxygen = float (input("Enter grams of oxygen entered into the reaction: "))
gramAcetaldehyde = float (input("Enter grams of acetaldehyde entered into the reaction: "))
print ("*" * 80)
moleOxygen (gramOxygen)
moleAcetaldehyde (gramAcetaldehyde)
gramOxygenAA (moleOxygen)
gramAcetaldehydeAA ()
limitingReagent()
print ("The number of grams of acetic acid produced due to limiting reagent is", format (smaller,'.2f'))
### Call to main program ###
main ()
我编辑的更改代码:
# Function that determines moles of oxygen input
def moleOxygen (gramOxygen):
molesOxygen = gramOxygen / (15.9994 * 2)
print ("Moles of oxygen available:", format(molesOxygen,'.2f'))
return (molesOxygen)
# Function that determines moles of acetaldehyde input
def moleAcetaldehyde (gramAcetaldehyde):
molesAcetaldehyde = gramAcetaldehyde / ((12.011*2) + (1.008*4) + 15.999)
print ("Moles of acetaldehyde available:", format(molesAcetaldehyde,'.2f'))
return molesAcetaldehyde
# Function that determines grams of Acetic Acid produced from available oxygen
def gramOxygenAA ():
gramsOxygen = (moleOxygen * (2/1)) * ((12.011*2) + (1.008*4) + (15.9994 * 2))
print ("Grams of Acetic Acid that can be produced from available oxygen is", format(gramsOxygenAA,'.2f'))
return gramsOxygen
# Function that determines grams of Acetic Acid produced from available acetaldehyde
def gramAcetaldehydeAA ():
gramsAcetaldehydeAA = (molesAcetaldehyde / (2/2)) *((12.011*2) + (1.008*4) + (15.9994 * 2))
print ("Grams of Acetic Acid that can be produced from available acetaldehyde is", format(gramsAcetaldehydeAA, '.2f'))
return gramsAcetaldehydeAA
# Function that determines the Limiting Reagent
def limitingReagent():
if gramsOxygen < gramsAcetaldehydeAA:
smaller = gramsOxygen
print ("Oxygen is the limiting reagent")
else:
smaller = gramsAcetaldehydeAA
print ("Acetaldehyde is the limiting reagent")
return smaller
def main ():
gramOxygen = float (input("Enter grams of oxygen entered into the reaction: "))
gramAcetaldehyde = float (input("Enter grams of acetaldehyde entered into the reaction: "))
print ("*" * 80)
moleOxygen (gramOxygen)
moleAcetaldehyde (gramAcetaldehyde)
gramOxygenAA ()
gramAcetaldehydeAA ()
limitingReagent()
print ("The number of grams of acetic acid produced due to limiting reagent is", format (smaller,'.2f'))
### Call to main program ###
main ()
但是我仍然遇到相同的错误...太可悲了...