Python IndentationError – Codecademy: Python basics: Pyg Latin 9/12

Question:

Here’s my code:

pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
first = word[0]


if len(original) > 0 and original.isalpha():
        if first in 'aeiou':
    print 'vowel'
            else:
                print "consonant"
        else:
            print "empty"

and here’s the confusing error message:

File “python”, line 10
print ‘vowel(‘
^) IndentationError: unindent does not match any outer indentation level

It says this (“) is the problem. I can’t really continue my learning of Python without my step.

Asked By: Faris Kapo

||

Answers:

pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
first = word[0]

if len(original) > 0 and original.isalpha():
    if first in 'aeiou':
        print 'vowel'
    else:
        print "consonant"
else:
    print "empty"

Indentation (the number of spaces from the left before each line of code) is important in Python. Each if and else must have the same indentation.

For instance…

if 1 == 1:

    else:

…will not work, because there’s 0 spaces before if and there’s 4 spaces before else. So each else that belongs to a if statement must be aligned.

Answered By: Torxed

you didn’t apply indentation for printing vowel..
try this

if len(original) > 0 and original.isalpha():
if first in 'aeiou':
    print 'vowel'
else:
    print "consonant"
Answered By: Kartik Sharma

Here, the error is coming because the print function and other are not in proper sequence some are out of loop that’s why, it is showing error
if you want to solve these type of questions then first learn that how to write something in a loop and just idetify which function or variable are under the defined loop

Answered By: Arman Soni
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.