Help with programming exercise

Hello, guys so I went ahead to do exercise 1 for the programming and when I ran the code it kept giving errors. I don’t know if I am doing something wrong.

{mentor edit: code removed}

Welcome to the community!

You’re missing the multiplication operator between ‘2’ and ‘m’.

Also please don’t post your code on the Forum. If a mentor needs to see your code, they’ll give you instructions for that.

You can always post any error messages or asserts, those are usually sufficient for us to diagnose most issues.

Thanks!

Oh, I am sorry about that. So I went ahead to add the multiplication in the code however I kept getting the error code for a
NameError Traceback (most recent call last)
in
4
5
----> 6 cost = compute_cost(x_train, y_train, initial_w, initial_b)
7 print(type(cost))
8 print(f’Cost at initial w: {cost:.3f}')

NameError: name ‘x_train’ is not defined

Hello @Chelnnexy, whenever you see a name is not defined, usually it’s because you didn’t run a previous code cell that define that name. Please make sure you have run all previous cells in order and if you have closed and reopened the jupyter notebook, you will need to run all of them again.

Raymond

Hello @rmwkwok, I ran the code as instructed but the error for the public test kept popping up. Also, I manually typed in (import public_tests) but the error still popped up.


AssertionError Traceback (most recent call last)
in
10 # Public tests
11 from public_tests import*
—> 12 compute_cost_test(compute_cost)

~/work/public_tests.py in compute_cost_test(target)
17 initial_b = 1.0
18 cost = target(x, y, initial_w, initial_b)
—> 19 assert cost == 2, f"Case 2: Cost must be 2 but got {cost}"
20
21 # print(“Using X with shape (5, 1)”)

AssertionError: Case 2: Cost must be 2 but got 0

Problem was resolved.