Search code examples
pythonlogical-operators

How to make a function with "not in" operator in Python?


I would like to write a function that test for each vowel whether it occurs in its parameter and returns False if text contains any lower-case vowel, True otherwise.

My code is as follow:

def hasNoVowel(text):
    return ('a' not in text) or ('u' not in text) or ('o' not in text) or ('i' not in text) or ('e' not in text) 
print(hasNoVowel('it is a rainy day'))
print(hasNoVowel('where is the sun?'))
print(hasNoVowel("rhythm"))

However the output that I get is:

True
True
True 

In stead of: False, False, True

Can someone help me and explain what I did wrong?

Thank you in advance!


Solution

  • You'll want to use and instead of or in your function. Currently your function returns False only if all five vowels are present:

    >>> print(hasNoVowel('she found the sun during a rainy day'))
    False