Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

313-7 getting value less than what was expected

https://app.dataquest.io/m/313/conditional-statements/7/combining-logical-operators

for row in apps_data[1:]:
   rating = float(row[7])
   genre = row[11]  
   price = float(row[4])
   if genre == ('Social Networking' or genre == 'Games') != 0:
       non_free_games_social_ratings.append(rating)
       
avg_non_free = sum(non_free_games_social_ratings) / len(non_free_games_social_ratings)

Right now I am getting a value less than what was expected. My rating is coming out as 2.9850299401197606 when it should be 3.8904235727440146.

What am I doing wrong?

Thanks for the help!

Hi @rahulkamalean

Welcome to our Dataquest Community.

You have applied the wrong condition in the if statement.

You have to append rating of non-free (price not zero) apps which have genre Social Networking and Games.

So you can do that in this way.

if genre in ['Social Networking', 'Games'] and price != 0:

or

if (genre == 'Social Networking' or genre == 'Games') and price != 0:

Hope this helps :slight_smile: .

3 Likes

hi, i’m new here.
i tried everything and i’m still getting an error
File “”, line 25
if (genre == ‘Social Networking’ or genre == ‘Games’) and price != 0:
^
SyntaxError: invalid syntax

https://app.dataquest.io/m/313/conditional-statements/7/combining-logical-operators

@KhaledHanafy,

The link does not lead to your code.

However, make sure that you close the parenthesis in the line before line the of code showing the SyntaxError . i.e

If it does not solve the problem, post more of your own code.

how do i add my code?

@KhaledHanafy, Just copy from the DQ code editor and paste here by putting it inside ``` and ```.

For future purposes, kindly check this link" Guide: How to Ask a Good Question