Week 4 assignement 2: I am Getting NameError: name 'compute_content_cost' is not defined

My code for function compute_content_cost_test(content_output, generated_output): is all good when I run the function from grader “compute_content_cost_test(compute_content_cost)” I am getting the following error:
NameError Traceback (most recent call last)
Input In [34], in <cell line: 3>()
1 ### you cannot edit this cell
----> 3 compute_content_cost_test(compute_content_cost)

NameError: name ‘compute_content_cost’ is not defined

but even though that cell is not editable…I am struggling with this issue with my notebook Please suggest any ideas regarding this issue. i have seen other notebooks online for the same exercise those grader functions are different from mine…How Can I overcome this?

Please run all the above cells.

RIght! Also are you sure that your compute_content_cost function doesn’t throw any compile errors when you click “Shift-Enter” on it?

Also note that copying solutions from GitHub is against the rules. It’s cheating and it may not always work in any case, because they have updated these assignments pretty frequently over time and what you found sounds like it must be an old version.

Yeah I ran several times it doesn’t work

yeah, I am sure that when I ran compute_content_cost it didn’t throw any error.
yeah I know copying from GitHub is false but I checked for the verification for this error

Are you sure that you didn’t accidentally convert the cell for compute_content_cost into a “markdown” cell instead of a code cell? There’s a menu item where you can check that and also change it.

Click “Cell → Cell Type → Code” to convert it to a code cell.

Either that or maybe you changed the spelling of the name of the function in the “def” statement.

BTW if you’re not able to tell whether the cell is code or markdown, try introducing an obvious syntax error like removing the close bracket from a line like this:

a_C = content_output[-1]

If it’s markdown, then nothing bad happens when you click “Shift-Enter” to run the cell with a syntax error in it.

I couldn’t find a cell for compute_content_cost. i could able to find cell compute_content_cost_test.

{moderator edit - solution code removed}

also I couldn’t able to find any line like the above
here below I have attached the lab id as well labid

It seems you edited the code which you were not supposed to do. Please note that you have to write your code between the comment lines ### START CODE HERE and END CODE HERE. You don’t need to change anything outside of these lines.

For now, read this instruction to get a clean copy of your assignment and then do your code at these specific places only.

It looks like you have modified the definition of that function: you changed the name from compute_content_cost to compute_content_cost_test. Why did you do that? If it was because you get an “undefined” message for compute_content_cost_test, that just meant that you hadn’t run the “import” cell at the beginning of the notebook.

You can just edit the name or you can do as Saif suggests and start over with a clean copy.

No, I don’t have access to edit the below shell. it was already pre-written like that as compute_content_cost_test

but I tried the said suggested method but it couldn’t get the clean copy. again got the same error Notebook

Paul is not talking about this cell but the one above it.

What issue did you get while getting the clean copy?

That just means you did not follow the instructions correctly. It clearly states that the procedure will not replace existing files, so you need to rename your notebook first. Please try again and read the instructions more carefully.

Here is the second paragraph of the instructions that Saif linked you to:

  • The first thing to do is to rename the existing notebook, because this procedure will not overwrite existing files. You need to move the current version of the notebook aside or delete it. The advantage of renaming is that you can later copy any completed work as desired to the fresh copy of the notebook.

sorry. It’s my bad I have deleted the.py file and now follow the procedure you mentioned. Now I got the Clean Copy Thanks

That’s good news, but there’s a “meta” lesson to be learned here: “saving time” by not reading instructions is not a good strategy. You save a minute and then waste 10 minutes or half an hour trying to figure out why it still doesn’t work.

Yeah…It’s true