The takeaway lesson here is that a loop of current will behave pretty much the same as an ordinary permanent magnet; that is, North and South poles will attract, while North-North and South-South combinations will repel.
This immediately gives us a simple explanation of how the “magneto-electric train” works! When we place our battery, capped with magnets, inside the coil, we complete a circuit and a current flows through the coil. The coil is, in essence, multiple loops of current stacked on top of one another, and the result is that the region of coil between the permanent magnets is a magnet itself!