Course 1, week 4 Exercise 9: problem in relu_backward_

Well, there must be something wrong with your logic in the loop. Are you sure you didn’t modify the “for” statement? Also note that indentation is a critical part of the syntax in python. The way you recognize the end of the loop is by the indentation, right?

The basic sequence is that you handle the output layer first before the loop starts. In this case, that would be layer 2. So you get dA1, dW2 and db2 as you say. Then you enter the loop and execute it once generating dA0, dW1 and db1.

I can’t see your code, so it’s up to you to figure out why the body of the loop is getting executed twice. If you think that you may have modified some of the template code that should not have been changed, there is a procedure documented on the FAQ Thread for getting a clean copy for comparison purposes.