Error in coding assignment

I am getting UnboundLocalError: local variable ‘v’ referenced before assignment error in my coding assignment Could someone please help?

Well, you don’t give us much information about which assignment this is, but the error message tells you exactly the question that you need to answer: where is v defined?

If this is the image2vector function in the Python Tutorial assignment in Course 1, Week 2, please note that this is the definition of the image2vector function:

def image2vector(image):

So that gives you a definition of image, but not of v, right?

1 Like

Right , but its showing that v has been referenced before the assignment I didn’t do that and I tried clearing the stored variables but it still shows the error.

I think you are just misinterpreting the error message. The python interpreter is telling you that your code references v before you have given a value to v. That probably means you used it on the RHS (Right Hand Side) of the expression where you should have used image. That was the point I was trying to make by showing the definition of the function.

“referenced before assignment” means you are referencing v before you have made an assignment statement that assigns a value to v. An assignment statement means something like:

v = 42.

That is an assignment statement which gives (assigns) a value to the variable v.

1 Like

Oh sorry
for me being silly and thanks for your help.

Hey @paulinpaloalto, which assignment is this ?

I believe it is the Python Tutorial Assignment: C1 W2 A1.

1 Like