Differences between revisions 2 and 8 (spanning 6 versions)
Revision 2 as of 2010-11-23 05:35:51
Size: 3082
Editor: Eviatar
Comment:
Revision 8 as of 2012-05-09 01:39:32
Size: 2948
Editor: jason
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
== Molar Mass Calculator == == Molar Mass Calculator FIXME ==
Line 10: Line 10:
{{{ {{{#!sagecell
Line 13: Line 13:
    '''Parses formulas and calculates molar mass using atomic weights at http://www.chem.qmul.ac.uk/iupac/AtWt/. It also shows the calculation used.'''     '''Parses formulas and calculates molar mass using atomic weights at http://www.chem.qmul.ac.uk/iupac/AtWt/'''
Line 21: Line 21:
            elementlist.append(element.group(a))             if element.group(a) != '':
    
elementlist.append(element.group(a))
Line 23: Line 24:
    for item in range(len(elementlist)):
        try: elementlist.remove('')
        except ValueError:
            break

    var(reduce(lambda x, y: str(x)+' '+str(y), elementlist))
    var(' '.join(str(x) for x in elementlist))
Line 79: Line 75:
            massfinder=re.compile('%s</td><td>\w+\s*</td><td>\[?(\d*\.?\d*)\]?\(?' %atom)             massfinder=re.compile('%s</td><td>\w+\s*</td><td>\[?(\d*\.?\d*)[](]' %atom)
Line 81: Line 77:
            elementlist[index]='decimal.Decimal("%s")' %found.group(int(1))             elementlist[index]='decimal.Decimal("%s")' %found.group(1)
Line 90: Line 86:
    elementlist=reduce(lambda x, y: str(x)+str(y), elementlist)     elementlist=''.join(str(x) for x in elementlist)
Line 95: Line 91:
def _(compound=input_box(label='Compound', default='H2O', type=str)): def calc(compound=input_box(label='Compound', default='H2O', type=str)):

Sage Interactions - Chemistry

goto interact main page

Molar Mass Calculator FIXME

by Eviatar Bach

molarmass.png

interact/chemistry (last edited 2012-06-13 06:35:25 by eviatarbach)