Connect the other terminal of the knife switch to the battery ... 4-inch nail. This is mechanical energy in action. The mechanical energy is caused by the attractive force of the electromagnet.
A simple electromagnet is made by coiling wire around an iron nail. An iron core makes a temporary electromagnet. It loses its magnetism as soon as the switch is opened and the current is switched ...