我尝试添加一个条件,如果while循环遇到“Y”或“y”,它仍会将字母移动到结尾,但在开头保持“Y”或“y”,但是循环将结束并添加“ay”
print("Pig Latin Translator Test!")
name = raw_input("What is your name, friend?")
if len(name) > 0 and name.isalpha():
print("Hello!")
else:
print("That's not a name!")
word = raw_input("What is your word?")
VOWELS = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")
YList = ("Y", "y")
if word[0] in VOWELS:
word = word + "yay"
else:
这是导致问题的部分:
while word[0] in YList or (not VOWELS):
word = word[1:] + word[0]
word = word + "ay"
print (word)
答案 0 :(得分:1)
(not VOWELS)
的值总是假的,因为VOWELS
是真的。
你打算写:
while word[0] in YList or (word[0] not in VOWELS):