Sergio
Sergio

Reputation: 53

While loop multiple conditions not working

I tried to add a condition to where if the while loop meets a "Y" or "y" it will still move the letters to the end, but keep "Y" or "y" at the beginning, yet the loop will end and just add "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:

This is the section causing problems:

    while word[0] in YList or (not VOWELS):
        word = word[1:] + word[0]
    word = word + "ay"
print (word)

Upvotes: 0

Views: 42

Answers (1)

Ray Toal
Ray Toal

Reputation: 88378

The value of (not VOWELS) is always falsy because VOWELS is truthy.

You meant to write:

while word[0] in YList or (word[0] not in VOWELS):

Upvotes: 1

Related Questions