Can some one find the error in this code? I want to create a function return result in boolean types when I enter a phrase which has vowel return true if not return false. However, I always took True even I avoid enter vowel in sentence

word = input(“Enter a phrase”)

def isVowelWorld(word):
word = word.upper()
vowels=“aoeui”
for vowel in vowels:
if vowel not in word:
return False
return True

result = print(isVowelWorld(word))

It’s a bit hard to tell without seeing the indentation.

One thing I notice is that you do word = word.upper(). So for example test will turn into TEST, and TEST doesn’t have any of those lower-case vowels.

Also it looks like you return False as soon as you see that a certain vowel is not in the word, but maybe you need to check all the vowels.

  1. Vowels are all lower case and word argument will always be converted to upper case so it will never match vowels.

  2. The Loop will exit immediately when you return.

Either remove “upper()” or convert vowels to uppercase.

In your current For loop, iterating on the first vowel in vowels will always return the result immediately and exit the loop.

Invert your IF statement to check if vowel in Word and return True, as the vowel exists in the word and doesn’t matter whether the remainder of the string has vowels because it is true regardless. Return False outside of the For Loop.

1 Like