Compilation error in W2 practice Lab

I am unable to figure out the mistake in this code cell

Hi, @Sanuraag_Mishra Please, don’t share your code as it’s against the Honor code only share the error you are getting.

Now, for the error, you are facing the code block of the for loop should be indented to be in the function block. you need just to indent the for loop block:

for something:

all should be indented.

Now, remove the image and share only the error

what does that mean?
I know C++ and how the for loop works but I am not understanding this point you made…

@Moaz_Elesawey could You see it now

Code block in C++ works by using the {} or the curly braces right, but in python, the code block is defined using indentation so to define a function for example in Python you do that

def function(parameter):

    return something

here you see everything in the function is indented using either spaces or tabs and they should be of the same length for all the lines in the.

Now, the error you get is that the compute_cost function is having a SyntaxError which makes it unrunnable and later causes the error in the next cell.

In the function, compute_cost make sure that everything in the function is indented at the same level, you also might encounter nested code block like you have a function and the function have a for loop inside it you define it like that:

def function(parameter):
    for i in range(10):

    return something

You see here that there is an indentation for the function body and inside it you have a for loop which itself has an indentation code block.

Make sure that all of that is done for you. and it will work just fine.

Every time you open the Notebook,
you must run all of the cells in sequence from the top.

The compute_cost() function is defined in the cell immediately before the cell in your image.

1 Like

yes I understood now the 1st issue I am facing is here

as @TMosh said you need to run all the previous cells before you run a specific cell you need just to run the cells before this one.


there is an error but I am not able to identify

All you need is to just start from the first cell at the top of the notebook and run it by using shift + enter. this will execute the cell and go to the next and keep doing so. and see what error now is shown.

remember the first cell.

@Moaz_Elesawey that is the 1st cell

1 Like

Are you sure, this is the first cell in the notebook?

now it seems to work

@Sanuraag_Mishra Glad to hear that.

Now does this mean I have some Logic error??

1 Like


Exactly, just read your implementation wisely and see where you screw up, and try to follow the mathematical equation provided to you in the notebook.



Amazing, You had just one exercise left.

1 Like

@Moaz_Elesawey Thanks a lot