Example usage

Here we will demonstrate how to use chemcalculator functions

Imports

from chemcalculator import compute_mass
from chemcalculator import moles_grams_converter
from chemcalculator import percent_mass

Calculating molar mass of a chemical formula

The compute_mass function calculates the molar mass of the entered chemical formula.

compute_mass("H2O")
18.013
compute_mass("C12H22O11")
342.275
compute_mass("Al2(SO4)3")
342.147
compute_mass("(NH4)HS")
51.10699999999999

Converting between grams and moles

The moles_grams_converter function converts the mass entered to grams or moles for the given chemical formula.

Converting from moles to grams:

moles_grams_converter("H2O", 0.05555, "moles")
1.001

Converting from grams to moles:

moles_grams_converter("H2O", 18.01528, "grams")
1.0

Calculating percent mass

The percent_mass function calculates the percentage mass of the sub-compound in the main compound.

percent_mass("H2O", "O")
The percentage mass of O in H2O is: 88.819 %
88.819
percent_mass("H2O", "H2")
The percentage mass of H2 in H2O is: 11.181 %
11.181
percent_mass("NaOH", "OH")
The percentage mass of OH in NaOH is: 42.519 %
42.519
percent_mass("Na(H2SO4)3", "NaH2SO4")
The percentage mass of NaH2SO4 in Na(H2SO4)3 is: 38.165 %
38.165