Exercise 8 of week 2 -Model

You are making other errors in the way you call optimize from model as well. Notice that you are using the variables X and Y to pass to optimize, but those are not defined within the “scope” of the model function. So you will end up referencing global variables for those, which will not end well.

The top level point is that calling a function in python is a completely different thing than defining a function in python. You can’t just “copy/paste” the definition of the function as the invocation of the function.

Also note that this specialization is not a beginning python course: it is assumed you already have reasonable competence as a python programmer before you start here. Here’s a thread from a while back that discusses the prerequisites for DLS. If you have good experience in other languages, then you can probably learn python on the fly here, but it will require that you go off and read some tutorials when you hit something new that trips you up like this case. But if the “learn on the fly” strategy is not working for you, then you might want to consider pausing this course and taking a python course first.