Coded using Python.