Python ';应为缩进块';

Python ';应为缩进块';,python,block,indentation,Python,Block,Indentation,我在以下行的冒号后面得到“预期的标识块”:def StartGame(用户名): 这一行的其余部分都是upp red,作为编程新手,我不确定自己做错了什么。提前感谢:) 看起来您正在混合制表符和空格。缩进使用4个空格: def StartGame(username): print("This game is all about Trading and Adventuring.") time.sleep(0.51) print("This is what is in you

我在以下行的冒号后面得到“预期的标识块”:def StartGame(用户名): 这一行的其余部分都是upp red,作为编程新手,我不确定自己做错了什么。提前感谢:)


看起来您正在混合制表符和空格。缩进使用4个空格:

def StartGame(username):
    print("This game is all about Trading and Adventuring.")
    time.sleep(0.51)
    print("This is what is in your inventory: %s" % Inventory)
    time.sleep(1)
    print("As you go around, you will start to lose hunger. You will need to buy food along the way.")
    time.sleep(1)
    print("You have %s Health Points (HP)" % UserHunger)
    TO.SetRandName()

另请参见。

看起来您正在混合制表符和空格。缩进使用4个空格:

def StartGame(username):
    print("This game is all about Trading and Adventuring.")
    time.sleep(0.51)
    print("This is what is in your inventory: %s" % Inventory)
    time.sleep(1)
    print("As you go around, you will start to lose hunger. You will need to buy food along the way.")
    time.sleep(1)
    print("You have %s Health Points (HP)" % UserHunger)
    TO.SetRandName()

另请参见。

4个空格表示缩进,您只使用了1或2,这就是为什么当它告诉您它需要缩进时,是因为您需要4个空格indent@Infamouslyuseless:Python实际上并不关心缩进有多大。你甚至可以在一个文件中混合和匹配缩进大小,尽管这样做是一个可怕的想法。@user2357112我知道,但通常人们使用4个空格,或者点击tab,这也是一样的,因为如果你知道我的意思,这看起来更整洁,更容易理解?@臭名昭著的无用:人们通常都这么做,但您的评论说,如果使用不同的缩进大小,Python会抱怨。Python不在乎。(另外,点击Tab并不等同于4个空格,除非您特别指示文本编辑器插入4个空格而不是一个选项卡。)@user2357112对于eclipse pydev,我认为Tab会自动执行,因为我没有告诉它,当我点击Tab时,它会自动执行4个空格…4个空格表示缩进,您只执行了1或2,这就是为什么,当它告诉您它需要缩进时,这是因为您需要有一个4空格indent@Infamouslyuseless:Python实际上并不关心缩进有多大。你甚至可以在一个文件中混合和匹配缩进大小,尽管这样做是一个可怕的想法。@user2357112我知道,但通常人们使用4个空格,或者点击tab,这也是一样的,因为如果你知道我的意思,这看起来更整洁,更容易理解?@臭名昭著的无用:人们通常都这么做,但您的评论说,如果使用不同的缩进大小,Python会抱怨。Python不在乎。(另外,点击Tab并不等同于4个空格,除非您特别指示文本编辑器插入4个空格而不是一个选项卡。)@user2357112对于eclipse pydev,我认为Tab会自动执行,因为我没有告诉它,当我点击Tab时,它会自动执行4个空格。。。