Week 2 Programming Assignment - Exercise 8 - model

Getting error - AssertionError: Wrong length for d[‘costs’]. 20 != 1. Please help

1 Like

The most common cause of that error is hard-coding the number of iterations to 2000 on the call from model to optimize. You should just be passing through the arguments from the invocation of model, right?


You are correct. All tests passed! . Thank you :slight_smile:

hi, please let me know what to do for this kind of error, I’m still not able to resolve.

When you call optimize from model, you need to be careful not to “hard-code” any of the values that you are passing. When you define (declare) a function, assigning a value to one of the parameters means that the parameter is optional and you have given the default value. But when you invoke (call) a function, saying something like:

retval = myFunction( ... , dayOfTheWeek = 3, ...)

Then myFunction will always get 3 as the value of that parameter. In our case, for example, look at how num_iterations is handled. It has a default value in the declaration of model, but you must pass through the actual value to optimize.

1 Like