C1 W2 Practice lab: exercise1

Hello all,
I am new at Python. Could anyone please help me do this assignment?
I face this error attached.

{moderator edit: code removed}

Plus, I don’t know where to write my code. I mean should I copy and paste: def compute_cost(x, y, w, b) and m = x.shape[0] and total_cost = 0 at the place on the cell where it is written: ###start code here####
?

Hi @Jaber_Sadeghiseraji ,

The lab assignment has template code for each exercise, you are required to add code between the comment lines:

START CODE HERE

END CODE HERE

There are two problems with your code

  1. def compute_cost(x,y,w,b):
    this declaration has already done at the top of this function, so the extra declaration is not needed
  2. the variable total_cost should be outside of the ‘for’ statement

Python uses indentation to construct codeblock. So incorrect indentation would cause the wrong code logic. Each indentation is 4 whitespaces.

If you have no programming experience at all, you might consider to pause this course and enrol to a beginner course on Python.

Here is link to a thread on Python learning resources.

Dear Kic
Many thanks for your help. Actually, you answered my second question regarding this lab (the point of For loop).
With regard to Python, I would say that I have been doing a Python course by self-study since some months ago.
Best regards

@Jaber_Sadeghiseraji, please do not post your code on the forum. That’s not allowed by the course Honor Code.

I have edited your message to remove the code.