Course 1, week4, assignment 1, ex5, append error

I’m new to Python. For ex5, for the test problem, I got error right after appending cache to caches. I printed out all the arrays (W, b, A[l-1], Z) and the ‘cache’, which contains, in sequence, A[l-1], W, b, Z. They appear to be the expected dimensions for the 3-layer net. I tried both append(cache) and append(list(cache)). Still no clue why append is not working. Any suggestion is welcome!

Here is the print out of cache before append

The error is that appending to the cache by using the “append” method does not require an assignment statement. That is what breaks things. You said this:

caches = caches.append(cache)

The correct implementation is just this:


You are invoking a method of the class object caches, which is an instance of the python class list. This is not just a python thing: all OO languages work this way.

Also please note that this course is not structured as an introductory programming course for python. You need to have reasonable competence as a python programmer as a “pre-existing condition” to succeed here. If this is an ongoing problem for you, you might want to consider pausing this course and spending some time learning python. If you are already a very experienced programmer in other languages (e.g. more than 2 years of serious experience in Java, C#, C++, JavaScript or some other high level procedural language), then you can probably “wing it” and learn python on the fly here. But if this is your first serious exposure to any kind of programming, you’d really be better off just taking a python course first.

Thanks, that was it. All tests passed for Ex5 now. I program with Fortran and, years ago, programmed with C to pass a HPC class. Have forgotten most of the C and don’t have any experience with object based programming. I took a " Crash Course on Python" on Coursera from Google. Don’t remember everything I learned. Old age! Would you have a recommendation for another Python course?

1 Like

The “Crash Course on Python” from Google is one of the top hits when I search for python on Coursera. Maybe if you took it again with a known goal in mind and a guaranteed way to practice what you are learning it would “stick” better this time.

The University of Michigan also has a specialization on Python for Data Science. That sounds like it might take a while to get through, though. Have a look and see what you think.

Thanks for the suggestion. I also found the “Tutorial” section of Python 3 documentation that appears to provide additional explanation of OOP.

1 Like