Right now my function is not recoginizing my numbers in the list coeff as numbers. I am trying to pair up items from the two list and then sort them into a different list based on the value of mul. But everything is going into the negative list. How to i make sure it is considering mul as a number going into each if statement.
def balance_equation(species,coeff):
data=zip(coeff,species)
positive=[]
negative=[]
for (mul,el) in data:
if mul<0:
negative.append((el,mul))
if mul>0:
positive.append((el,mul))
Edit;
I ment to originally include this
balance_equation([‘H2O’,’A2′],[‘6′,’-4′])
Your problem is that in the way you call it (
balance_equation(['H2O','A2'],['6','-4'])),mulis a string rather than an int ('6'or'-4'rather than6or-4). Change your if statement to:This converts
multo an integer before comparing it to 0.