0

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
3
  • 4
    Welcome to SO! The indentation is invalid. Please fix and thanks (you can't have an elif just hanging out without an associated if). Commented Aug 24, 2019 at 3:12
  • when i used the indentation, it showed indentation error, so instead i just removed indentation. Before the elif statement, the code is running fine with the if statement. after the elif statement, its throwing an error (?) Commented Aug 24, 2019 at 3:22
  • The if is syntactically valid and its block ends and the outer main scope resumes. But then, out of nowhere, there's an elif without an if before it. A minimal reproducible example of this error is the following program (run it for yourself): elif True: print("hello world"). Commented Aug 24, 2019 at 3:31

1 Answer 1

3

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.")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.