C1_W2_Assignment Help with code error

Hello

this is continuation from my previous topic

this is the full error message

NameError Traceback (most recent call last)
in
26
27
—> 28 for i in range(m):
29
30

NameError: name ‘m’ is not defined

I can provide the full code upon request

Please provide a link to your previous topic.

I don’t think it’s really helpful but sure

For example, ‘m’ is defined by the one of the lines of code in the compute_cost() function cell:

When the compute_cost() function is called with the appropriate parameters for x, y, w, and b, the ‘m’ variable will be set to match the number of rows in the ‘x’ matrix. That is, the number of training examples in the ‘x’ data set.

If you’re working on the gradient_descent() function, there is a similar line of code there for the ‘m’ value.

I think you are better to check the indentation level, which is an essential to define a code block for Python.

Here is a good summary by Raymond.

In your case, I guess, even “m” is defined before, if an indentation of “for i in range(m):” is not correct, then, this is a possible error. Here is an example of a bad case.

And, here is a good case.

Please double check.

1 Like

oh thank you for this answer my code works perfectly now!

Hello Friends , I am beginner , I faced an issue where I get this message. “ File “”, line 29
return total_cost
^
IndentationError: expected an indented block

image

Pleasehelp me What i do ?

Correct indentation is critical when programming in python. It uses indentation to identify blocks of code.

If you do not have experience programming in python, I recommend you take a python tutorial course right now, and come back to this course later.

Thanks for the suggestion. Pls suggest how can take ?

There are lots of python courses and tutorials available online.

Here is one (it’s a series of videos organized in a playlist).
https://www.youtube.com/playlist?list=PLJR1V_NHIKrCkswPMULzQFHpYa57ZFGbs

Thanks for guide me