Write a molar mass calculator that reads formulas such as Ca(OH)2, then programs for moles, the limiting reagent, the yield, and the volumes in a dilution or a titration.
3 lessons, about 1 h 25 min3 simulations10 problems3 practice questionsPython in every lesson
A molar mass is a sum: atomic mass times the count, for every element. A dictionary holds the atomic masses, and a regular expression reads the symbols and counts out of a formula. Brackets are opened first. The same function then gives the percent composition of any compound.
A balanced equation fits naturally into two dictionaries, one for the reactants and one for the products. A function changes grams to moles, finds the limiting reagent as the smallest number of rounds of the equation, and returns the products and the excess. Then it is tested against a case worked by hand.
Molarity is moles of solute per litre of solution. Small functions find the mass to weigh for a solution, the volume of stock for a dilution, the concentration after mixing and the end point of a titration. A loop then prints the acid left as the base runs in.
Log in to join the discussion.
Loading…