例如,如果我输入 bob
,它应该给我 obb
。同样,像 plank
这样的东西应该给我 ankpl
。
s = input("What word do you want translated?")
first = s[0]
vowel = "aeiou"
for i in range (1, len(s)):
if first in vowel:
s = s + "way"
print (s)
else:
s = s[1:] + s[0]
print (s)
这目前只给我 lankp
for plank
。
谢谢!
最佳答案
它实际上可以变得更简单:
s = raw_input("What word do you want translated?").strip()
vowel = set("aeiou")
if vowel & set(s):
while s[0] not in vowel:
s = s[1:] + s[0]
print s
else:
print "Input has no vowels"
关于Python程序连续将辅音移动到字符串的末尾,直到第一个字母是元音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19828561/