WK4 assignment: unindent error

My code works well but once I submitted it, I always received 0 grade because of “There was a problem compiling the code from your notebook. Details:
unindent does not match any outer indentation level (, line 113)”. I do not have line 113 in my code. Anyone can help?

The grader environment must be different and less “forgiving” than the online notebook environment. The graders are a black box here, meaning we don’t actually know how they work, but one theory is that they extract the code cells from the notebook and then concatenate them into a new python “dot py” file and then run that with an added “main” function to test your functions. So perhaps there are more than 113 total lines of code in your notebook and that might be a clue as to where to look for the error. Indentation is part of the syntax of python, of course, so it matters. Maybe the error is that you mixed tabs and spaces to create some of the indentation and the online environment is ok with that, but the grader is not. The error message should give you some fragment of the code that is another clue as to where to look for the problem. Go through and check to make sure you haven’t mixed tabs and spaces anywhere would be my first suggestion.

Hi Paul,

Thank you for your help. I had been working on this for a few days: I manually removed all indents and tried tabs only or spaces only. But this problem still exists so I cannot pass this assignment. Do you mind taking a look at the code I have?

Thank you again.


I have not taken that specialization, so I don’t know if I will be able to help. But I can try to take a look. Maybe before we go to that step, a more productive next step would be to try getting a clean copy of the notebook and then carefully “copy/pasting” over just your completed code segments from the existing notebook. There is a topic on the DLS FAQ Thread that explains how to get a clean copy.

My theory there is that you have accidentally damaged some of the “template” code …

Hi Paul,

I agree with your working theory. I actually deleted a few lines of code in the template when I was testing what the line 113 refers to. I will check whether I am able to recover the code and resubmit.



Hi Paul,

I added the code I deleted but even though the code runs as it expected and the model stops after 11 epochs with an accuracy rate of .99, the system still sent back a “0” grade with the same info saying the line 113 has an unindented error. I attached the notebook in this email and hope you have time to take a quick look and give me more help. I am stuck on this assignment for two weeks and cannot proceed.



{moderator edit - solution code removed}

Note that the grader only grades the Official version. If your clean plus paste version has a different file name, the grader is still looking at the old one.

I will download your notebook and take a look within an hour or so …

It looks like there is an extra leading space on this cell:


Hi Paul,

Thank you very much. This is the reason for the error. I removed the space, resubmitted my work and passed. I am lucky to get your help.

Have a great weekend.


Glad to hear that was the solution. It’s kind of amazing how much trouble a single space in the wrong place can cause. Programming is always a game of details, but this seems like a pretty extreme case. :scream_cat: :nerd_face: