Code - Comparison Operators


I’m working on comparison operators and received an output that shows I have the correct answers. However, I keep receiving a “TypeError: ‘int’ object is not iterable” message. Can somebody help me figure out where I’m messing up at?

Here’s the link to problem and my code:

Hi @mensahkk!

I’m not sure if the code in the link is yours or my own from that mission - could you please copy and paste your code here?

Make sure you surround it with backticks like so for readabilty:

your code here

Thanks for responding, Slavina!

Let me know if I copy and pasted my code correctly (I’m new to Dataquest).

opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

n_apps_more_9 = 0

for row in apps_data [1:]:
rating = float(row[7])
price = float(row[4])

if price > 9:
    n_apps_more_9 = n_apps_more_9 + 1

avg_rating = sum(n_apps_more_9) / len(n_apps_more_9)

n_apps_less_9 = 0

for row in apps_data [1:]:
price = int(row[4])
if price < 9:
n_apps_less_9 = n_apps_less_9 + 1


My last message didn’t show the indentations I had for the loop formulas.

Try using ``` instead of … to surround your code block and it should render as in a code editor!

The error message you are getting is seriously baffling me because it doesn’t make much sense; however, I do see errors in your code. Editing to add: I can see it now: the sum() function expects an iterable, but n_apps_more_9 is an integer.

A hint: on line 9 in your screenshot, you correctly retrieve the rating for each row -however, you don’t do anything with this value later.

Line 13 is incorrect, can you see why?

That was very helpful! Thanks for your help.

1 Like

You’re welcome!

If you consider your question to be solved, you can mark it as such for the benefit of other students like so:

To mark an answer correct:

  1. Scroll down to the correct post
  2. Click on the three dots next to the reply button
  3. Click the check box. It will then show up in the original post as solved.
1 Like

Done! Thank you again.

1 Like