An electromagnet is made from a coil of wire that acts as a magnet when…