# If i > 0 <= 500000: rating_dict["below 500000"] += 1 condition not working properly

i am trying to create a frequency table for `[row 5]` in apps_data.csv, which describes the total number of user ratings an app has received, and displaying it in frequencies of (‘below 500000’: 0, ‘500000 - 1000000’: 0, ‘1000000 - 1500000’:0, ‘1500000 - 3000000’:0)

``````opened_file = open('AppleStore.csv')
opened_file.close()

ratingslist =[]
rating_dict = {'below 500000': 0, '500000 - 1000000': 0, '1000000 - 1500000':0, '1500000 - 3000000':0}
for i in apps_data[1:]:
ratingCount = int(i[5])
ratingslist.append(ratingCount)

maximun = max(ratingslist)
minimum = min(ratingslist)

for i in ratingslist:
if i > 0 <= 500000:
rating_dict["below 500000"] += 1
elif 500000 > i <= 1000000:
rating_dict["500000 - 1000000"] += 1
elif i > 1000000 <= 2500000:
rating_dict["1000000 - 1500000"] += 1
else:
rating_dict["1500000 - 3000000"] += 1

print(maximun)
``````

output i got is:

2974676

``````print(rating_dict)
``````

the output i got is:

{‘below 500000’: 6268, ‘500000 - 1000000’: 929, ‘1500000 - 3000000’: 0, ‘1000000 - 1500000’: 0}```

HELP, The maximum value in the list is 2974676, but if elif condition is not adding it to the "‘1500000 - 3000000’ dictionary.

Please use triple back ticks ````` to format a code block. See the post below on how to format code block using triple back ticks.

`i am trying to create a frequency table for [row 5] in apps_data.csv,`which describes the total number of user ratings an app has received, and displaying it in frequencies of (‘below 500000’: 0, ‘500000 - 1000000’: 0, ‘1000000 - 1500000’:0, ‘1500000 - 3000000’:0)```

``````from csv import reader
opened_file.close()```

```ratingslist =[]
rating_dict = {'below 500000': 0, '500000 - 1000000': 0, '1000000 - 1500000':0, '1500000 - 3000000':0}
for i in apps_data[1:]:
ratingCount = int(i[5])
ratingslist.append(ratingCount)```

```maximun = max(ratingslist)```
```minimum = min(ratingslist)```

```for i in ratingslist:
if i > 0 <= 500000:
rating_dict["below 500000"] += 1
elif 500000 > i <= 1000000:
rating_dict["500000 - 1000000"] += 1
elif i > 1000000 <= 2500000:
rating_dict["1000000 - 1500000"] += 1
else:
rating_dict["1500000 - 3000000"] += 1```

```print(maximun)
output i got is:
2974676```
```print(rating_dict)
the output i got is:
{'below 500000': 6268, '500000 - 1000000': 929, '1500000 - 3000000': 0, '1000000 - 1500000': 0}```

HELP, The maximum value in the list is 2974676, but if elif condition is not adding it to the "'1500000 - 3000000' dictionary.
``````

I have edited your original post and properly formatted it. Please take a look at it to get an idea of what kind of formatting is suitable and to see how to apply such a formatting.

Now, coming to your question -

When you write the code -

the above is an equivalent of two checks -

1. It checks if `i` is greater than `0`.
2. It checks if `0` is less than or equal to `500000`

That’s not the logic you need. You need to check if -

1. `i` is greater than `0`, and
2. `i` is less than or equal to `500000`

The above is equivalent to -

``````0 < i <= 500000:
``````

Take note of the position of the numbers and `i` as well as the comparison operators. That’s the logic you want.

Based on that, update your `if` and `elif` conditions.

Secondly, this part of your code -

You are trying to check if `i` is in the range of `(1000000, 2500000]`, however, you are updating the `"1000000 - 1500000"` dictionary key instead. The upper limit does not match for those two - one is `2500000` and the other is `1500000`.

Fixing and updating your code based on the above should give you the desired answer.