Python Basics with Numpy --Avoid Using Global Variables inside the Function

In the Python_Basics_with_Numpy assignment, in Cell #4 on the function for basic sigmoid, I get an error message that says avoid using global variables in the function. However, I did not use any global variables; I only assigned the sigmoid value to “s” and the code passes the test for correctness. How do I avoid the global variables error?

basic_sigmoid(1) = 2.718281828459045
Error: Wrong output.
1 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in
1 print("basic_sigmoid(1) = " + str(basic_sigmoid(1)))
2
----> 3 basic_sigmoid_test(basic_sigmoid)

~/work/release/W2A1/public_tests.py in basic_sigmoid_test(target)
21 ]
22
—> 23 test(test_cases, target)
24
25 def sigmoid_test(target):

~/work/release/W2A1/test_utils.py in test(test_cases, target)
24 print(‘\033[92m’, success," Tests passed")
25 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
—> 26 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for basic_sigmoid. Check your equations and avoid using global variables inside the function.

Hi @Chris_Lewis, check for any close parenthesis that you are missing in the equation. Thanks.

That is just one possible suggestion of the error. The error is clear from looking at your result for basic_sigmoid(1): the answer you get is just e, right? So you took the instructions a bit too literally: when they said to use math.exp to implement sigmoid, they didn’t just mean that is all you need. math.exp(x) is just e^x. Take another look at the formula for sigmoid, as given in the instructions. It’s a bit more complicated than that, right? :smiley:

The other clue is that the whole point of sigmoid is that it converts the input into something that looks like a probability, meaning that it’s between 0 and 1. So 2.7182… can’t possibly be correct.

You are so right! I realized I mistakenly thought the formula was too rudimentary. For those who are encountering the same “global variables” error, I encourage you to go back to the mathematical formula for the sigmoid function and make sure that you implement the entire formula in your code.