You will write three small functions that name and sort the straight-chain alcohols. The name comes from the number of carbons and the place of the OH group.
The idea. The chain is numbered from the end that gives the OH carbon the lower number. The name is the stem, then an, then the number, then ol. Methanol and ethanol have no number, because there is only one place for the OH.
Your tasks.
lowest_locant(chain, position) so that it returns the lower of the number counted from the left and the number counted from the right.name_alcohol(chain, position) so that it returns the name, such as butan-2-ol. Use lowest_locant.classify(chain, position) so that it returns "primary" when the lowest locant is 1, and "secondary" otherwise.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…