Magnet is a material that has the ability to produce a magnetic field on the outside, which is capable of…