|
Size: 3082
Comment:
|
Size: 2948
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)): |
