LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Code checker seems to approve incorrect code

Screen Link: https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/8/finding-the-unique-values

Your Code: ```opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

#content_ratings = {}

for row in apps_data[1:]:
c_rating = row[10]
if c_rating in content_ratings:
content_ratings[c_rating] += 1
else:
content_ratings[c_rating] = 1

print(content_ratings)```

What I expected to happen: The first time I wrote this, I forgot to create the content_ratings dictionary. When I ran the code, it worked anyway. When I submitted the code, I got the “Nice Work!” message.

What actually happened: I can run this with ```content_ratings = {}`` commented out or not and get the same result.

Other details: Am I missing something? I don’t want to think my code is correct if it isn’t.

Thanks for reporting this issue. I have been able to identify what is causing this problem on our end, and I have logged it to be fixed so that the answer without defining the dictionary first won’t pass.

Thank you! My real concern is not just this specific case but whether the code checker is, for example, only checking final answers but might not catch errors in the code. I hope that makes sense.

Generally, our answer checking mechanism works by looking at the variable state at the end of your code.

If your code would produce an error (in which this case it normally would), the code will error and the screen will not pass.

In this case, we’ve used the same variable in two consecutive screens without clearing it inbetween, which is why your code didn’t fail when you forgot to initialize the dictionary. This is a relatively rare case, so I wouldn’t expect that there would be many instances where incorrect code wouldn’t pass our answer checker.

I hope this helps to shed some light on how things work behind the scenes.

That helps a lot - thanks!