Code not working

content_ratings = {‘4+’: 4433, ‘12+’: 1155, ‘9+’: 987, ‘17+’: 622}
total_number_of_apps = 7197
for erating in content_ratings:
props[erating]=content_ratings[erating] / total_number_of_apps
perc[erating]=prop[erating] * 100
percentage_15_allowed=perc[‘15+’]
percentage_17_plus=perc[‘17+’]
print(percentage_15_allowed)
print(percentage_17_plus)

I am trying to understand why it’s not working

I wanted to assign “content_ratings[erating] / total_number_of_apps” to a variable then use it to perform percentage, that way I could extract percentage_17_plus directly, but it’s not working out

Hi @jordangarden55 , welcome to the forums!

In order to do what you want to do, you would need to initialize both props and perc as empty dictionaries before the loop (props = {} and perc = {}). Then Python can populate each dictionary with the results of each line in the code. (Though there’s a typo in the 5th line to fix first.)

It’s possible to do everything without having to create 2 additional dictionaries though. You can reassign the results back to the original dictionary using content_ratings[erating] instead of props[erating], for example. It will update the values of the content_ratings dictionary.

I hope that helps.