First please make sure from indentation it is correct but I think you made a great space(tab) specially in the first loop(outer nested loop), Second before the return and after the loop you want to divide the dj_db, and dj_dw by m
Apologies, but this is not a code which I have written, it is from the practice lab session which I have used to just mention about the error term I wanted to know