python - Write the function startEndVowels(word) that returns True if the word starts and ends with vowels -




for below program getting output as:

true false none false 

expected should :

true false true false     

what wrong code?

def startendvowels(word):     vowels = "aeiou"     x = word[0]     y = word[-1]     z = len(word)     if z >1:        if x in vowels:           if y in vowels:              return true        else:             return false     elif z == 1:          if word in vowels:             return true          elif x == " ":               return false print startendvowels("apple") print startendvowels("goole") print startendvowels("a") print startendvowels(" ") 

you use startswith , endswith method accept tuple of possible prefixes/suffixes:

def startendvowels(word):     vowels = tuple("aeiouaeiou")       return word.startswith(vowels) , word.endswith(vowels) 

the reason why function didn't work because didn't check capitalization. either need include upper case vowels too:

vowels = "aeiouaeiou" 

or cast word lower-case:

word = word.lower() 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -