Content_ratings isn’t defined in your code, but we expected it to be dict type

Screen Link:
https://app.dataquest.io/m/425/functions%3A-fundamentals/2/built-in-functions

My Code:

ratings = ['4+', '4+', '4+', '9+', '12+', '12+', '17+', '17+']
content_ratings = {'12+' : 0,  '17+' : 0, '4+' : 0, '9+' : 0 }
#print(content_ratings)
for age in ratings:
    if age in content_ratings:
        content_ratings[rate] += 1
    else:
        content_ratings[rate] = 1
print(content_ratings)

What I expected to happen:
{‘17+’: 8, ‘4+’: 0, ‘12+’: 0, ‘9+’: 0}

What actually happened:

 content_ratings ()
- actual + expected

- [undefined]

content_ratings isn’t defined in your code, but we expected it to be dict type

You need to first define an empty dictionary.
content_rating = {}

Also since you are creating a frequency table with age as the key, you need to append the dictionary using this key.

for age in ratings:
    if age in content_ratings:
        content_ratings[age] += 1
    else:
        content_ratings[age] = 1

Hope this will solve your issue.

2 Likes

Yes i solved the problem right after i post. Thank you