【发布时间】:2015-07-27 11:22:00
【问题描述】:
编写函数 startWithVowel(word),它接受一个单词作为参数,并返回一个从单词中找到的第一个元音开始的子字符串。如果单词不包含元音,则该函数返回“No vowel”。
例子
>>> startWithVowel('apple')
'apple'
>>> startWithVowel('google')
'oogle'
>>> startWithVowel('xyz')
'No vowel'
我的答案
def startWithVowel(word):
if word[0] in 'aeiou':
return word
elif word[0] != 'aeiou' and word[1:] in 'aeiou':
return word[1::]
elif word not in 'aeiou':
return "No vowel"
我的问题 如果单词包含任何元音,我知道如何删除第一个元音字母,但我坚持使用此代码..使用此逻辑它应该为 xyz 返回“无元音”。 但它返回'yz',我知道我错了,这是第4行的逻辑问题。但我不知道如何解决这个问题。
【问题讨论】:
标签: python