Your code is not calculating costs correctly. When you loop over each training example i, make sure that the model’s prediction for that example is computed correctly inside the loop:
f_{wb}(x^{(i)}) = wx^{(i)} + b,
as well as the cost for that example,
cost^{(i)} = (f_{wb} - y^{(i)})^2,
and add total_cost = total_cost + cost, the cost from each iteration to a variable (total_cost) initialized outside the loop.
Then you can return the total_cost as total_cost divided by 2m outside the loop.