Unexpected Output on Filtering for the Intervals 13/ 15 (Dictionary and Frequency Tables)

Screen Link:

What I expected to happen:
I expected my dictionary to come up with intervals (keys) and numbers of rating count (values).

What actually happened:

the frequence do not show up as the way I expect. Only the first interval has value, rest intervals (“10000 - 100000”), to the rest) have the value zero.

@NguynTrungNgha: mind if you provide the question link?

yea, so the task is to create the dictionary with intervals are the rating count (extracted from the data set named apps_data has an index of 5) and the frequency ( how many rating counts it belongs to each intervals ).
unexpected output: only the first interval counts (“0 - 100000” : 1016) the rest of the intervals are 0 (“10000 - 100000” : 0)
expected output: all of the intervals must have values

Ok understand the issue. Mind if you copy paste your code here so I can just use that to troubleshoot as I cant copy the code from the screenshot…

@NguynTrungNgha: I spotted some errors.

For the first condition, you are checking for ratings below 10 MB. So you should use the less than or equal to (<= sign) instead of >=. If you use >= this will result in the if statement being true all the time and all the frequency values being stored as values of the '0 - 10000' key, whilst the rest of the elif statements being skipped since the 1st condition is already met.

Also, you are missing one of the ranges of the data bytes and some of the ending values are not correct.

The if - else block should look like this:

if user_ratings <= 10000:
     user_ratings_freq['0 - 10000'] += 1
elif 10000 < user_ratings <= 100000:
     user_ratings_freq['10000 - 100000'] += 1
elif 100000 < user_ratings <= 500000:
     user_ratings_freq['100000 - 500000'] += 1
elif 500000 < user_ratings <= 1000000:
     user_ratings_freq['500000 - 1000000'] += 1
elif user_ratings > 1000000:
     user_ratings_freq['1000000+'] += 1

ahhh thank you so much, I’m so dumb. By the way, your variable names looking more straight foward than mine.
No no, the task was

so my interval lengths are pretty wide and I’m lazy also. and the values used in this task are users rating not data sizes

thanks again for your help :smiley:

Ahh i see… No problem. Your welcome. Anytime.

1 Like