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.

Était-ce utile?

La solution

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"

Python builds on identantion, meaning: The number of spaces from the left right before each code starts. Also, Each if and else must coexist on the same identation, For instance:

if 1 == 1:

    else:

Will not work, because there's 0 spaces before if and there's 4 spaces befor else.
So each else that belongs to a if statement must be on a veritical alignment.

Autres conseils

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"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top