You will write four small functions that you can use again for every question about formulae. One gives the number of hydrogen atoms of an alkane. One finds the relative formula mass. One decides which family a formula belongs to. One counts the bonds in the displayed formula of an alkane.
The idea. The alkanes are , the alkenes , the alcohols in all and the carboxylic acids in all, where is the total number of carbon atoms. The relative formula mass uses C = 12, H = 1 and O = 16. An alkane has C-C bonds and one C-H bond for each hydrogen atom.
Your tasks.
alkane_hydrogens(n).relative_mass(c, h, o).family(c, h, o) so that it returns "alkane", "alkene", "alcohol" or "carboxylic acid", and "other" for anything else. Assume that there are no rings.bonds_in_alkane(n).Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…