Please correct the code and add comments where correction is done.
I would correct your code and would mention comments also.
But, I would first suggest you to go through the following code:
Datatypes matter like float for median.
The logic is what has been explained in the video.
If you still face issue, let me know.