The reactivity series is a list in order, from potassium at the top to gold at the bottom. A metal displaces another from a solution of its salt if it is earlier in the list. A program can hold the series as a list, use the index of a metal as its place, and test the rule with index comparison. A model is tested against known results, and it has limits. Potassium, sodium and calcium react with the water of the solution first, and the model says only if a reaction happens, not how fast.
This is the first lesson of Metals and Non-metals: Python Challenge Lab, free for everyone to read.
In the chapter, you learned the reactivity series: potassium at the top, gold at the bottom. A series is just a list in order. And the rule of displacement can be said in one line:
A metal displaces another from a solution of its salt if it is earlier in the list.
A program is good at a rule like this. It does not get tired, and it does not forget a pair. With a list of eleven metals, there are pairs to check. By hand, that is a long job. For the program, it is a fraction of a second.
The place of a metal in the list is its index: for potassium, for sodium, and so on. A smaller index is a more reactive metal. So the rule is that series.index(metal) < series.index(other). If this is true, the metal displaces the other. If it is false, there is no reaction.
The rule is a model. A model is a simple idea that we use to predict. We ask: does it agree with what we see?
A model is useful when it agrees with what we see. We know three results.
If the program says the same for all three, the model works. If it says something different for even one, then the model, or the list, has a mistake.
True if the first is earlier than the second.You should find that doubling the list from to metals almost quadruples the number of tests.
Every model has limits. A good scientist says what they are.
This program tests some pairs with the rule.
<.series.index("Li") gives an error until you add it.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
series of the lesson, what is the index of iron?Metals and Non-metals: Python Challenge Lab is a Standard course. It adds 2 more lessons, practice and tests on top of the free chapter.