简体   繁体   中英

my code keeps showing syntax error in my elif/else statements

I'm trying to make a basic pig latin translator but the editor keeps showing me a syntax error.

ay = "ay"

way = "way"

consonants = ("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z")

vowels = ("a", "e", "i", "o", "u")

user_word = input("Enter your word here: ")

first_letter = user_word[0]

first_letter = str(first_letter)

first_letter = first_letter.upper()

if first_letter in consonants:

        print(first_letter + "is a consonant.")

remove_first_letter = user_word[1:]

pig_latin = remove_first_letter + first_letter + ay

print("The word in Pig Latin is " + pig_latin)

elif first_letter in vowels:

        print(first_letter + "is a vowel.")

pig_latin = user_word + way

print("The word in Pig Latin is " + pig_latin)

else:

        print("I don\'t know what" + first_letter + "is.")

This is what i have come up with. The exact error message that it shows is:

File "<ipython-input-33-8e1536233f19>", line 14

    elif first_letter in vowels:

       ^

SyntaxError: invalid syntax

Python is an indentation-dependent language. elif and else need to be at the same depth as if , and whatever statement depends on the condition needs to be indented further.

For example:

if first_letter in consonants:
    print(first_letter + "is a consonant.")
    remove_first_letter = user_word[1:]
    pig_latin = remove_first_letter + first_letter + ay
    print("The word in Pig Latin is " + pig_latin)
elif first_letter in vowels:
    print(first_letter + "is a vowel.")
    pig_latin = user_word + way
    print("The word in Pig Latin is " + pig_latin)
else:
    print("I don\'t know what" + first_letter + "is.")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM