Question: why does my code return a value of zero . Python code : import numpy as np # Given reaction mechanism ( coefficients are already

why does my code return a value of zero .
Python code :
import numpy as np
# Given reaction mechanism (coefficients are already corrected)
finput=[
"C3H8<-> CH3*+ C2H5*",
"C3H8+ H*<-> H2+ C3H7*",
"C3H7*<-> C3H6+ H*",
"C2H5*<-> C2H4+ H*",
"C3H7*<-> C2H4+ CH3*",
"C2H5*+ C3H8<-> C2H6+ C3H7*",
"CH3*+ C3H8<-> CH4+ C3H7*",
"CH3*+ C3H7*<-> C3H6+ CH4"
]
reactions = list()
for line in finput:
stripped_line = line.strip()
if stripped_line[0]=='#':
continue
if stripped_line[:2]=='..':
continue
for r in reactions:
i = reactions.index(r)
species_tmp = list() # temporary list for species
for r in reactions:
left = r.split('<=>')[0].strip() # reactants side
right = r.split('<=>')[1].strip() # products side
left_terms = left.split('+') # reactant species w/ stoichiometric coeff.
right_terms = right.split('+') # product species w/ stoichiometric coeff.
terms =[t.strip() for t in left_terms]+[t.strip() for t in right_terms] # concatenate list comprehensions
for i in terms:
tmp = i.split('') # split stoichiometric coefficient from species name
assert len(tmp)==1 or len(tmp)==2,' terms =%r, i =%r, tmp =%r '%(terms, i, tmp)
if len(tmp)== f=2:
species_tmp.append(tmp[1].strip()) # species name if there is a stoichiometric coeff.
else:
species_tmp.append(i.strip()) # species name if there is no stoichiometric coeff.
species_filtered = set(species_tmp) # filter species as a set
species = list(species_filtered) # convert species set to list
print('
species =
',species)
print('# of species =',len(species))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!