Organic chemistry describes the branch of chemistry that deals with molecules containing carbon. The main atoms that make up molecules in organic chemistry are carbon (C), oxygen (O), hydrogen (H), nitrogen (N), and sulfur (S). For example, CH4 represents a molecule composed of one carbon atom and four hydrogen atoms, or the amino acid methionine, which has the structural formula C5H11NO2S, consists of 5 carbon atoms, 11 hydrogen atoms, 1 nitrogen atom, 2 oxygen atoms, and 1 sulfur atom
Organic compounds such as methionine are essential for living organisms. The average atomic mass of the five key atoms is shown in the table below. The mass of a molecule is calculated by adding together the masses of the atoms. For example, the mass of a CH4 molecule is 12.01 + 4 * 1.01, which equals 16.05.
atoom | massa |
---|---|
C | 12.01 |
O | 15.99 |
H | 1.01 |
N | 14.01 |
S | 32.07 |
write a function is_organic
that checks whether the molecule consists only of the five key atoms and does not contain any other atoms. The input for this function is a string variable for a molecule and a tuple ‘atoms_organic_chemistry’ ‘see tip’.
write a function atoms_molecule
that takes an organic molecule as input and returns a tuple as output with the number of atoms of each type. For example, for C-H4, the tuple would be (1, 0, 4, 0, 0), where the elements respectively represent the number of C-atoms, O-atoms, H-atoms, N-atoms, and S-atoms.
write a function mass_molecule
that calculates the molecular mass using the tuple from the function ‘atoms_molecule’ and returns it as a floating-point number. For example, for (1,0,4,0,0), the output would be 16.05.
write a funtion mass_organic_molecule
that calls the previous functions. If the input is an organic molecule, the message “the mass is nn.nn” is returned, where nn.nn represents the mass. Otherwise, the message “that is not an organic molecule” is printed.
atoms_organic_chemistry
of the five key atoms in organic chemistry, where each element is a string of the atom’s symbol.>>> is_organic("C-H4", atoms_organic_chemistry)
True
>>> atoms_molecule("C-H4")
(1, 0, 4, 0, 0)
>>> mass_molecule((1, 0, 4, 0, 0))
16.05
>>> mass_organic_molecule("C-H4")
"the mass is 16.05"
>>> mass_organic_molecule("Na-Cl")
"that is not an organic molecule"