C3_W1_Anomaly_Detection UNQ_C2: Got compile error when I submit my assignment

I just got a very weird problem, for the UNQ_C2 in C3_W1_Anomaly_Detection, my code can pass all the unit tests by clicking the Run all option in the Cell menu, but when I try to submit my assignment, it said:

Cell #UNQ_C2. Can't compile the student's code. Error: IndentationError('expected an indented block', ('/tmp/student_solution_cells/cell_11.py', 56, 8, '        if (tp + fp) == 0:\n'))

Please help me, I have already been stuck in here for 2 hours and have no idea why.

1 Like

Hi @winsonli

To fix this error, you need to check the indentation of the line causing the issue and make sure that it is properly aligned within the block it belongs to. In this case, it is related to the line that contains: if (tp + fp) == 0:.

1 Like

I know what you mean, but I think the indentation is ok in my code, that’s why I said it’s weird, please help me check my code.

My code can pass all the unit tests by clicking the Run all option in the Cell menu

Thanks.

That is weird! Sometimes copy-pasting code from other sources can insert invisible characters or formatting issues. Try retyping the code manually to resolve this problem and do not remove any comments or codes that you are not allowed to.

If the issue persists, feel free to send me your code via private message so that we can work on the code together.

Here is a common way this issue happens:

If you use the Hint code in the notebook, it doesn’t have the correct indentation. This is because it’s embedded in a Markdown cell.

If you copy the Hint code and put it into a Code cell, you can sometimes get indentation issues. The notebook kernel seems to handle it OK, but the grader does not.

You can tell if you have this issue because certain parts of your code will appear in a red font.

That means the parser isn’t happy with the formatting of your code.

The code is totally written by myself, not copy-paste even a letter. I already send you the code via private message, please check it.


Thanks a lot.