C1W2 Cell#8 Can´t compile student´s code

I obtained the same results provided with my code, but when I send my code for evaluation, I get this message:
Cell #8. Can’t compile the student’s code. Error: SyntaxError(‘invalid syntax’, (‘/tmp/student_solution_cells/cell_8.py’, 10, 7, ‘You can check if your implementation was correct by running the following test code:\n’)
a) I don’t know how to locate cell # 8
b) I don’t know where I can get the rest code mentioned.
Did anyone have this message and solve it?
Thanks for helping

Can you share more details about the error like in which section of the notebook are you getting an error?
Is it while computing the cost function or while computing the Gradient Descent?

I don’t get any error mesage while running the cells I coded; my results are the same as the output expected. In every section I get the message like this
a) Gradient at initial w, b (zeros): -65.32884974555672 -5.83913505154639
Using X with shape (4, 1)
All tests passed!

b) Gradient at test w, b: -47.41610118114435 -4.007175051546391

Expected Output:

Gradient at test w -47.41610118 -4.007175051546391
c) w,b found by gradient descent: 1.166362350335582 -3.63029143940436

Expected Output:

w, b found by gradient descent 1.16636235 -3.63029143940436

As you see, all the code runs well

The issue happened to me when I used Jupyter magics such as %%time in a code cell, so if you could try removing such Jupyter magics, then re-run the whole notebook from start, that should be fine.
Let me know.

I already sent you the file

Thank you Ricardo. I ran your notebook from the beginning, and found that you might have unintentionally turned one of the markdown cells into a code cell

To change it back, select the cell, then on the menu bar, click “Cell” > “Cell Type” > “Markdown”.

Also, as you can see in my screenshot, on the left of the cell it says In [8]: which means it’s the 8th code cell being executed, so I think this was what the error message implied.


Thanks, Raymond, I will try this out later; I have some work pending to do, too.

No problem!


Raymind, sorry I am back again with a query: I changed the cell type to Markdown, but see what it looks like, it appears as simple text:


GRADED FUNCTION: compute_cost

def compute_cost(x, y, w, b):
Computes the cost function for linear regression.

    x (ndarray): Shape (m,) Input to the model (Population of cities) 
    y (ndarray): Shape (m,) Label (Actual profits for the cities)
    w, b, m: (scalar): Parameters of the model

    total_cost (float): The cost of using w,b as the parameters for linear regression
           to fit the data points in x and y
# number of training examples
m = x.shape[0]

Raymond, please disregard my message; I misunderstood you, but now it runned OK. Thank you very mucho and I apologize for being so hard-head.

1 Like

Hey Ricardo, no problem at all. We are here to help.

I am getting back late because I just wake up - I am in Hong Kong, but I am glad to see that you figured it out quickly.

Let us know if you have new questions:)


1 Like

Good morning, Raymond.

Thank you again.

Hi Ajay!

I have just seen your message; fortunately I could solve the problem with the help of Raymond Kwok and it was related to the definition of a cell: it was marked as markup.

Thank you very much for your suggestion