4
$\begingroup$

Write a program that determines the molecular weight of a chemical compound based on the number of hydrogen, carbon, and oxygen atoms in the compound. You should use the following atomic weights: \begin{array}{|c|c|c|c|} \hline \text{Atom} & \text{Weight}~\pu{gm/mole} \\\hline \ce{H} & 1.0079 \\\hline \ce{C} & 12.011\\\hline \ce{O} & 15.9994\\\hline \end{array}

I don’t understand the relation between molecular weight and the number of $\ce{H}$, $\ce{C}$, and $\ce{O}$.

The professor has said "there is no need to be able to handle chemical compound names like $\ce{H2O}$ or $\ce{C2H5OH}$. (I plan to discuss how to handle these later in class) Instead, the user should just be asked to specify the number of hydrogen, carbon, and oxygen atoms in the compound.”

I need help to proceed.

$\endgroup$
13
$\begingroup$

It's pretty simple actually. The molecular weight of a compound is the sum of the atomic weights of all its atoms. The same numbers apply to a single atom as for a mole of that atom, but at the single-molecule level the unit of measure is the atomic mass unit or amu (aka the dalton or Da). The number of grams per mole of an element and the number of daltons that a single atom of the element weighs are intrinsically linked due to the definition of what a mole of something is (the amount of a pure chemical substance that weighs the same amount in grams as the mass of one atom or molecule of the substance in daltons).

So, methane (CH4), for instance, has a molecular weight of 1.0079 x 4 + 12.011 = 16.0426 Da. A mole of this gas would weigh 16.0426 grams (which is - interesting science fact - lighter by almost half than that of N2 or O2 gases making up most of the atmosphere, so a balloon of it will float). So, your Python script would simply prompt for the number of hydrogens (accepting integer values only), carbons (ditto) and oxygens (ditto), and plug them into the expression:

total_mass = num_hyd * 1.0079 + num_carb * 12.011 + num_oxy * 15.9994

... before returning total_mass as the answer.

Theoretically, the energy contained as enthalpy in the bonds between atoms contributes to a molecule's mass by general relativity and the first law of thermodynamics. In practice, the amount of energy inherent in even the least stable bonds (which produce the most net energy when they decompose to form more stable ones) is a rounding error when you run it through E=mc2, and so chemists don't bother. Nuclear physicists, who actually change the atoms themselves, do care, because the equation works in reverse for them; they get lots of energy from very small changes in the atomic masses of the reactants vs the products.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.