Tuesday, 30 January 2018

python - Query about IF statements

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]
if genre=='Games'or 'Social Networking':
games_social_ratings.append(rating)
print(len(games_social_ratings))
print(len(apps_data))


I am working through an online coding course which imports a bunch of data on apps on the appstore and asks us to work out the average rating of games or social networking apps. When doing so I accidentally typed the if statement as shown above:




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


Heres what I dont understand, there are in total 7197 apps, if I use the above IF statement, the length of my games_social_rating list is 7197. The total number of games apps are 3862 and the total number of social networking apps are 167. Where is the number 7197 coming from? Can someone tell me what the computer is doing when I type in the above code? I would've thought an error would come up instead.



My only reasoning is that 'social networking' registers as a true statement and thus since the sentence



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



reads
if genre=='games' or true:



In which case it would append every item in the list. But why would it be a true statement?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...