Python缩进错误-Codecademy:Python基础:Pyg拉丁语9/12

Python缩进错误-Codecademy:Python基础:Pyg拉丁语9/12,python,indentation,Python,Indentation,这是我的密码: 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"

这是我的密码:

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”,第10行 打印元音(' ^)缩进错误:未缩进与任何外部缩进级别不匹配

它说这就是问题所在。没有我的步骤,我真的无法继续学习Python

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基于idention构建,意思是:在每个代码开始之前,从左到右的空格数。此外,每个
if
else
必须在同一个标识符上共存, 例如:

if 1 == 1:

    else:
将不起作用,因为在
if
之前有0个空格,在
else
之前有4个空格

因此,属于
if
语句的每个
else
都必须处于真实对齐状态。

您没有为打印元音应用缩进。。 试试这个


Codeacademy课程真的没有提到正确的缩进在Python中有多么重要吗?它应该是你学习Python的第一件或第二件事。@DanielRoseman:不,它确实多次提到过这一点。顺便说一句,我不确定pyg的作用是什么,但我把它放在那里了,即使你在这段代码中没有使用它。。对我来说也不只是一个例子求我这么做。谢谢,这真是一个很好的解释。是的,我有点不知道那些空格,我只是在看“写的(?)”代码。我想是一个noobmistake@user3261814错误时有发生:)这是在IDE或更高级的文本编辑器(如*Sublime text 3)中销售的好时机,它将自动缩进:)
if len(original) > 0 and original.isalpha():
if first in 'aeiou':
    print 'vowel'
else:
    print "consonant"