lundi 30 janvier 2017

Python 3: elif statements being skipped over in an if statement

I'm trying to write an if statement with elif statements and then an else statement at the end, except its completely skipping over my elif statements and it executes the else statement no matter what (even the if statement).

    word = input('Enter an all lowercase word to be translated: ')

    if word[:1] == ('a', 'e', 'i', 'o', 'u'):
        print(word + 'way')
    elif word[:2] ==('a', 'e', 'i', 'o', 'u') :
        print(word[1:] + word[0] + 'ay')
    elif word[:3] == ('a', 'e', 'i', 'o', 'u'):
        print(word[2:] + word[0:] + 'ay')
    else:
        print(word)

if i delete the last elif and else statements and turn the first elif statement into an else statement, it'll run through exactly how I want it to but I need the elif statements.

    if word[1] == ('a', 'e', 'i', 'o', 'u'):
        print(word + 'way')
    else:
        word[2] ==('a', 'e', 'i', 'o', 'u')
        print(word[1:] + word[0] + 'ay')

Aucun commentaire:

Enregistrer un commentaire