Looping over dict

Screen Link:https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/10/looping-over-dictionaries

Your Code: ""for rating in content_ratings:
content_ratings[rating] /=total_number_of_apps
content_ratings[rating] *= 100

percentage_17_plus = content_ratings[‘17+’]
percentage_15_allowed = content_ratings [‘4+’]
content_ratings[‘9+’] + content_ratings[‘12+’]

I could run my code
but when submitted ““Your code doesn’t seem to have the correct side-effects. Please re-check the instructions and your code.””

Hi and welcome to the community @prem_gv!

Seems like you might be missing a plus sign here.

percentage_15_allowed = content_ratings [‘4+’]  + # <- you need a plus sign here
content_ratings[‘9+’] + content_ratings[‘12+’]

if I add “+” and i run the code
following error shows

“” File “”, line 9
percentage_15_allowed = content_ratings [‘4+’] +
^
SyntaxError: invalid syntax

Is that line of code in 1 line, or in separate lines?

The code is in one line

Since questions 2&3 ask for percentages, shouldn’t we have divided by total_number_of_apps?

Hi @gkpvao, yes that should be done as implemented in the original code as shown below.

I was referring to those, but checking again I understand that the dictionary values have been already transformed to percentage by the previous loop hence we just need to use percentage_17_plus = content_ratings[‘17+’]

1 Like

Hello team. I am also facing the same issue on this step. :fearful:
“Your code doesn’t seem to have the correct side-effects. Please re-check the instructions and your code”

Hello,
@prem_gv initially I had the same issue and really ‘ate’ my time trying to troubleshoot, just to realize I had mistakenly altered the value of the variable “total_number _of_apps” which should be 7197.
This resolved the error “Your code doesn’t seem to have the correct side-effects. Please re-check the instructions and your code.”

I’m also facing the same issue

“Your code doesn’t seem to have the correct side-effects. Please re-check the instructions and your code.”.

It got resolved when I used shorthand operators *= and /= .
I hope it will help someone.

Hi prem_gv!

You’re adding the last three content_ratings together for the variable percentage_15_allowed. The answer lists them on a next line and my guess is due to space limits from formatting.