Beispiel #1
0
 def test_magnesium_hydroxide(self):
     p = Parser()
     self.assertEqual(p.parse_molecule(magnesium_hydroxide), {
         'Mg': 1,
         'O': 2,
         'H': 2
     })
Beispiel #2
0
 def test_fremy_salt(self):
     p = Parser()
     self.assertEqual(p.parse_molecule(fremy_salt), {
         'K': 4,
         'O': 14,
         'N': 2,
         'S': 4
     })
Beispiel #3
0
 def test_water(self):
     p = Parser()
     self.assertEqual(p.parse_molecule(water), {'H': 2, 'O': 1})
Beispiel #4
0
from parse import Parser
print('################################################')
print('From a chemical formula, this code outputs atoms')
print('that make up the chemical unit and their numbers')
print('################################################')
print('')
print('Type chemical formula to be parsed:')

formula = input()

p = Parser()
print(p.parse_molecule(formula))