Python Implementation of the HW3