NLP C1 WEEK 3 grader not giving correct grade

Yes, I looked at your notebook and you made exactly the mistake I was describing:

Within the body of the function get_country, you directly reference word_embeddings. That is a global variable that happens to be passed to that function as the parameter embeddings. So it works in the notebook, because you happen to accidentally be referencing the same dictionary that is actually passed by that test case. But it is a bug, because what happens if the grader passes a different dictionary as the embeddings parameter? That is why you fail the grader’s test.

You should only reference embeddings within get_country.

If you don’t understand how the concept of “scope” works in python, it would be a good idea to google “variable scope python” and read some tutorials about that. This is not a beginning python course: you need to already be a reasonably competent python programmer to succeed here. The concept of “scope” is present in all procedural languages more complicated than BASIC and python’s version of scope is one of the fairly simple ones: no “block level” scope, just function body local scope and global scope basically.

2 Likes