You will write a checker for chemical equations. It adds up each atom and the charge on both sides, and it tells you which items do not balance.
The idea. Each species is a dictionary of atoms, with the key "charge" for its charge. A coefficient multiplies everything in a species. An equation is balanced when every atom and the total charge are equal on the two sides.
Your tasks.
total(side, key) so that it returns the sum, over the species of one side, of the coefficient times the amount of key.is_balanced(left, right) so that it returns True when every key has equal totals on both sides.unbalanced(left, right) so that it returns the sorted list of keys that do not balance.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…