Exercise 11, Dictionaries and Frequency Tables


I keep getting an error on my last line (line 9) of code, saying “TypeError: ‘float’ object does not support item assignment”.

Can someone please explain why this is occurring and how to fix it ?
Thank you :slight_smile:

content_ratings = {'4+': 4433, '12+': 1155, '9+': 987, '17+': 622}
total_number_of_apps = 7197
c_ratings_proportions= {}
c_ratings_proportions = {}
for key in content_ratings:
    proportion = content_ratings[key]/total_number_of_apps
    c_ratings_proportions[key]= proportion
    percentage = proportion*100
    c_ratings_percentages[key] = (percentage) 

Hi @tfel4139,

The issue I see is that you forgot to assign an empty dictionary to c_ratings_percentages before the for-loop. Instead, you assigned twice c_ratings_proportions by mistake.

1 Like