Is_english function always returning True

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

Your Code:

def english_only(string):
    non_ascii = 0
   
    for character in string:
        if ord(character) > 127:
            non_ascii += 1
    
    if non_ascii > 3:
        return False
    else:
        return True

print(english_only('testing'))
print(english_only('fdgsddgsgfd欢乐 颂 电 视剧热播'))
print(english_only('Instachat😜😜😜😜😜😜'))
print(english_only('Docs To Go™ Free Office Suite'))
print(english_only('😜testing'))

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?

1 Like

Hey, Evan.

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?

1 Like

A post was split to a new topic: Fix is_english function

Hello Bruno,
I see your point, the bottom two strings are English but my concern is for the Instachat😜😜😜😜😜😜 and 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
...     else:
...         return True
... 
>>> print(english_only('testing'))
True
>>> print(english_only('fdgsddgsgfd欢乐 颂 电 视剧热播'))
False
>>> print(english_only('Instachat😜😜😜😜😜😜'))
False
>>> print(english_only('Docs To Go™ Free Office Suite'))
True
>>> print(english_only('😜testing'))
True

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.

2 Likes