And/or statements, appending, syntax and results

I am hoping to understand why the answer is different and how the code is being computed:

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

games_social_ratings =
for row in apps_data[1:]:
rating = float(row[7])
genre = row[11]
# Complete code from here

**if genre == 'Social Networking' or genre == 'Games':**


Here, the output was: 3.655994043186895

But, when I originally (accidentally?) wrote the ‘if genre…’ statement like this:

if genre == ‘Social Networking’ or ‘Games’:

…my output was lower at 3.526955675976101

After reviewing the expanded list at we get once we complete a mission, it appears that 10% my accident syntax included ratings not expected by the mission’s answer and did not include rates that were expected to be in the answer as well. Again, the majority of the expected answers did appear.

Question: I am really just curious about why this would generate different answers, and how the code is computing slightly different results for:

genre == ‘Social Networking’ or genre == ‘Games’
genre==‘Social Networking’ or ‘Games’

…and what is the importance of that second ‘genre ==’ part!

Thank you!

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

1 Like