我的代码问题在这里。当我输入ONLY辅音时,程序会卡住。但是当我输入混音辅音和元音时,它按预期运行。
例如:
感谢您是否可以帮助我。谢谢。
Deque
答案 0 :(得分:0)
最简单的解决方案(不过多修改代码)是检查一个单词没有元音时的特殊情况。
ignoreCase = "quit"
vowels = "aeiou"
while True:
# Get word and convert to lower case
word = input("Enter a word ('quit' to quit): ").lower()
if word == ignoreCase:
break
elif word == "":
print("Can't convert empty string. Try again.")
else:
# Starts with a vowel
if word[0] in vowels:
print(word + "way")
# Starts with a consonant
else:
# Only run loop if word has vowels
if any(char in vowels for char in word):
while word[0] not in vowels:
word = word[1:] + word[0]
print(word + "ay")