I have an error in week2 assignment

How can I fix this error

That error means that you have not run all the earlier cells in the notebook. You need to do that every time you open the notebook. Try “Cell → Run All Above” and then run that test cell again. You can examine the earlier cells in the notebook and search for the “import” commands. That’s where the test functions are loaded.

If this is your first time using the Jupyter Notebooks, it is a mistake to “save time” by not watching the video “A Quick Intro to the Jupyter Notebooks”. It’s been a while since I watched that and read the “Programming FAQ” reading item in Week 2, but I’m pretty sure they cover the point about “importing” the utility functions.

I watched it already and tried running all cells above and did not work. I believe the problem is in the second cell which I can not even edit.

Please try these steps:

  1. Kernel → Restart and Clear Output
  2. Save
  3. Cell → Run All

and see what happens to your test cell.

I tried it and unfortunately same error is appearing.

Actually the “import” command is in that same cell with basic_sigmoid. Are you sure you didn’t modify those lines? Here’s what the beginning of that cell should look like:

import math
from public_tests import *

# GRADED FUNCTION: basic_sigmoid

def basic_sigmoid(x):
    Compute sigmoid of x.

    x -- A scalar

    s -- sigmoid(x)
    # (≈ 1 line of code)
    # s = 

Are those first two lines there in your version of the code?

I did not modify it but I have the first line only.

You must have modified it accidentally then. You can get a fresh copy of the notebook by following the instructions on this thread.

In case there was other accidental damage, my suggestion would be to start over with a clean copy from scratch and reimplement things.

I just got a clean copy and both lines are there in my copy. The “tl;dr” of how to get the clean notebook is:

  1. Rename the current version
  2. Help → Lab Help → Get Latest Version

You must either rename or delete the current notebook first because the “Get Latest Version” will not overwrite any existing files.

Okay I will try it right now. Thank you so much for your help. I appreciate it.