Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

Why is my function returning False? ( Guided Project: Profitable App Profiles for the App Store and Google Play Markets)

Screen Link:
https://app.dataquest.io/c/115/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/7/removing-non-english-apps-part-two

My Code:

def string_func(a_string):
    
    for char in a_string:
        
        if ord(char) > 127:
            return False
        
        return True
        
print(string_func('Instagram'))
print(string_func('爱奇艺PPS -《欢乐颂2》电视剧热播'))
print(string_func('Docs To Go™ Free Office Suite'))
print(string_func('Instachat 😜'))

What I expected to happen:
According to the assignment, the last two functions should output ‘False’ because the string contains characters outside the ASCII range (0 - 127). The characters outside the range of ASCII are ‘™’ in ‘Docs To Go™ Free Office Suite’, and ‘:stuck_out_tongue_winking_eye:’ in ‘Instachat :stuck_out_tongue_winking_eye:’.

What actually happened:
I get ‘True’ instead of ‘False’, I can’t figure out why.

#OUTPUT
True
False
True
True

Guys, never mind! Let me explain what I did wrong in case somebody in the future encounters the same issue.

It was a dumb mistake.

My code was:

def string_func(a_string):
    
    for char in a_string:
        
        if ord(char) > 127:
            return False
        
        return True # <--- this line was the issue; I made an indentation error :(
    return True #<--- this line is correct, now it's returning False, as expected!
        
print(string_func('Instagram'))
print(string_func('爱奇艺PPS -《欢乐颂2》电视剧热播'))
print(string_func('Docs To Go™ Free Office Suite'))
print(string_func('Instachat 😜'))

#OUTPUT
True
False
False 
False