Cannot figure out error of Exercise 4 - initialize_with_zeros

Here is the code. I checked again and again but cannot find where went wrong…

[Code removed by moderator]


dim = 2
w, b = initialize_with_zeros(dim)

assert type(b) == float
print ("w = " + str(w))
print ("b = " + str(b))

initialize_with_zeros_test(initialize_with_zeros)


here is the result:

AssertionError Traceback (most recent call last)
in
2 w, b = initialize_with_zeros(dim)
3
----> 4 assert type(b) == float
5 print ("w = " + str(w))
6 print ("b = " + str(b))

AssertionError:

Many thanks.

Welcome, @QQ518. In general, the test code checks some of the output to verify that it satisfies certain properties. Here, it threw an AssertionError because b is not of the proper type. It should be a floating point number (Python type float), and clearly, it is not.

Most likely because your function assigned it as type int i.e. and integer. The easiest way to avoid this is to use a decimal point in the assignment statement. For example, x = 2. versus x = 2 does the trick. Using the Python function x = float(2) also does the job, but it’s more cumbersome.

As a reminder, learners are not allowed to post their code in the Discourse forum, or any other public forum for that matter. It is a violation of the course honor code. Thanks!

Thank you very much Kenb. Yes the decimal worked. And I am sorry for posting the code. I will check what others are doing and won’t make it happy again. Thanks again. :)