This is the function’s definition in the solution notebook:
def is_english(string):
for character in string:
if ord(character) > 127:
return False
return True
How about another way around if we want to iterate to check the number associated with the character is lesser than 127 and return True first for english text then else false for character more than 127. I’m still not able to get the code right if we want to accept english text with less than 4 non-english characters. Please advise.
def is_english(string):
non_ascii = 0
for character in string:
if ord(character) <= 127:
non_ascii += 1
if non_ascii < 4:
return True
else:
return False
print(is_english('Docs To Go Free Office Suite'))
print(is_english('Instachat 😜😜😜'))