You will write four small functions for cracking equations. One finds the atoms that are left over. One says what kind of molecule the left-over atoms make. One checks that an equation is balanced. One counts the ethene molecules that a cracking makes.
The idea. A molecule is written as a pair of numbers, (carbon atoms, hydrogen atoms). An equation side is a list of (number of molecules, carbon atoms, hydrogen atoms). The alkanes have hydrogen atoms, the alkenes , and hydrogen is .
Your tasks.
leftover(reactant, known) so that it returns the (carbon, hydrogen) that is left when the known products are taken away from the reactant.kind(c, h) so that it returns "alkane", "alkene", "hydrogen" or "not a molecule".balanced(left, right).ethene_count(big, alkane) so that it returns the number of ethene molecules made when the alkane big cracks into the alkane alkane and ethene only. Each of them is a pair (c, h).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…