Blue Week Special Offer | Brighten your week!

Comparison Operators

Screen Link:

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

n_apps_more_9 =

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

if price > 9.0:

avg_rating = sum(n_apps_more_9) / len(n_apps_more_9)
n_apps_more_9 = len(n_apps_more_9)
n-apps_less_9 = len(apps_data[1:]) - len(n_apps_less_9)

Replace this line with your code

What I expected to happen:
I expected its the same as the answer

What actually happened:
File “”, line 17
n-apps_less_9 = len(apps_data[1:]) - len(n_apps_less_9)

SyntaxError: can't assign to operator

The error is specified in the error message -

n-apps_less_9 = len(apps_data[1:]) - len(n_apps_less_9)

You use a - in the name of the variable, n-apps_less_9 instead of an _. It throws the error because it thinks - is a subtraction operation on the left hand side of the assignment operator (=).

So, just rename it to use the right character, _, and it should be fine.

1 Like

Thank you.

I corrected that but still giving this error message.

TypeErrorTraceback (most recent call last)
in ()
14 avg_rating = sum(n_apps_more_9) / len(n_apps_more_9)
15 n_apps_more_9 = len(n_apps_more_9)
—> 16 n_apps_less_9 = len(apps_data[1:]) - len(n_apps_more_9)

TypeError: object of type ‘int’ has no len()

That’s a separate error.

You have the following code line -

n_apps_more_9 = len(n_apps_more_9)

You store the length of n_apps_more_9 in n_apps_more_9. So, after the above code line, the n_apps_more_9 variable is storing an integer value.

Then, when you do

n_apps_less_9 = len(apps_data[1:]) - len(n_apps_more_9)

You are trying to calculate the length of that same variable, n_apps_more_9, again. You can’t calculate the length of an integer and hence you get the error.

You will have to be more mindful of naming your variables here. If you keep replacing variables with different values, you will run into such errors and it can also make it difficult for you to debug those errors. I would recommend being more careful about what kind of variable names you choose for different operations.


Thank you @the_doctor. I changed the variable names and it worked.