Python Forum

Full Version: SyntaxError: invalid syntax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm working on some problem and the goal is to count the frequency of each interval. There is a table with ratings ( sixth row ).

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
user_ratings = []
for row in apps_data[1:]:
    n_user_ratings.append(int(row[5])
                        
ratings_max = max(n_user_ratings)
ratings_min = min(n_user_ratings)
                       
user_ratings_freq = {'0 - 10000': 0, '10000 - 100000': 0, '100000 - 500000': 0,'500000 - 1000000': 0, '1000000+': 0}
    
for row in apps_data[1:]:
    user_ratings = int(row[5])
                        
    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
                        
print(user_ratings_freq)
Error:
ratings_max = max(n_user_ratings) ^ SyntaxError: invalid syntax
Any idea why this error appeared?
Search your code for other occurrences of max.
My guess would be that it got redefined somewhere, probably by mistake.
Count parentheses on line-7.
(Mar-10-2020, 02:45 AM)snippsat Wrote: [ -> ]Count parentheses on line-7.

after I made a correction got this error:
Error:
NameErrorTraceback (most recent call last) <ipython-input-1-0c555430149c> in <module>() 5 user_ratings = [] 6 for row in apps_data[1:]: ----> 7 n_user_ratings.append(int(row[5])) 8 9 ratings_max = max(n_user_ratings) NameError: name 'n_user_ratings' is not defined
...and made a correction in line 5 and now it's OK. Thank you.