Peter Otten wrote: > Alistair King wrote: > > >> the code works great now. I know these things are quite simple to learn >> from books etc.. but i would be lost without this mailinglist, from lack >> of time. Hopefully soon i can give something more complicated. >> I ended up doing the dictionary formatting properly and the new code is: >> > > >> heavy = raw_input("\n\n@@@@@@@@@@@@@@@@@@\n\nPlease enter the heaviest >> atom for which you obtained percentage values for, but not Oxygen or >> Hydrogen, ie, 'C', 'N', 'S', 'Br'...: ") >> >> def updateDS1v(Fxas, x): >> if Fxas !=0 and DS1v.get(x)!=None: >> value = DSvalues.get(heavy) >> floatvalue = float(value) >> atoms = DS1v.get(x) + Fxas*floatvalue >> else: >> value = DSvalues.get(heavy) >> floatvalue = float(value) >> DS1v[x] = Fxas*floatvalue >> >> updateDS1v(FCas, 'C') >> updateDS1v(FHas, 'H') >> updateDS1v(FOas, 'O') >> updateDS1v(FNas, 'N') >> updateDS1v(FSas, 'S') >> updateDS1v(FClas, 'Cl') >> updateDS1v(FBras, 'Br') >> updateDS1v(FZnas, 'Zn') >> > > >> it works perfectly now >> > > Probably not. Have you manually verified the result with more than one > example? Where does 'heavy' come from? Is that black hole 'atoms' > intentional? > > # I'm just guessing here > for k, v in DSvalues.iteritems(): > DSvalues[k] = float(v) > > def updateDS1v(Fxas, x): > DS1v[x] = DS1v.get(x, 0) + Fxas*DSvalues[x] > > Peter > yea...sorry i snipped one line by accident for the email should be:
def updateDS1v(Fxas, x): if Fxas !=0 and DS1v.get(x)!=None: value = DSvalues.get(heavy) floatvalue = float(value) atoms = DS1v.get(x) + Fxas*floatvalue DS1v[x] = atoms else: value = DSvalues.get(heavy) floatvalue = float(value) DS1v[x] = Fxas*floatvalue thanks a -- Dr. Alistair King Research Chemist, Laboratory of Organic Chemistry, Department of Chemistry, Faculty of Science P.O. Box 55 (A.I. Virtasen aukio 1) FIN-00014 University of Helsinki Tel. +358 9 191 50392, Mobile +358 (0)50 5279446 Fax +358 9 191 50366 -- http://mail.python.org/mailman/listinfo/python-list