Screen Link: https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/7/removing-non-english-apps-part-two
non_ascii = 0
for character in string:
if ord(character) > 127:
non_ascii += 1
if non_ascii > 3:
print(english_only('fdgsddgsgfd欢乐 颂 电 视剧热播'))
print(english_only('Docs To Go™ Free Office Suite'))
This is for the first python project where a function is used to remove non-english apps by returing True or False based on whether or not their is more than 3 non_english characters. This should return False for 2 strings at the bottom of the code. It is actually returning True each time. This is straight from the solutions manual, can someones help me understand why?
This is correct.
Given the above, let me ask you this: Do you see more than three non-english characters in the two bottom strings?
A post was split to a new topic: Fix
I see your point, the bottom two strings are English but my concern is for the
fdgsddgsgfd欢乐 颂 电 视剧热播 strings which are returning True when they should return False. I may have phrased this poorly before.
Maybe it’s just a bug on my end but I’m getting True for every string.
That shouldn’t be happening. See the expected result:
>>> def english_only(string):
... non_ascii = 0
... for character in string:
... if ord(character) > 127:
... non_ascii += 1
... if non_ascii > 3:
... return False
... return True
>>> print(english_only('fdgsddgsgfd欢乐 颂 电 视剧热播'))
>>> print(english_only('Docs To Go™ Free Office Suite'))
Are you running this locally in a notebook? Share with us.
My mistake. The code is running fine now.
I’m fairly certain I was running into trouble because I added an extra indent to the second if statement and the else statement. I must have copied and pasted the wrong code, sorry for the trouble and thank you for the help.