'期待一个缩进块'

时间:2013-09-14 21:10:24

标签: python block indentation

我在行上冒号后得到'预期的一个标识块':def StartGame(username): 对于其余部分来说,它是红色的,并且是编程的新手,我不确定我做错了什么。谢谢你提前:))

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()

1 个答案:

答案 0 :(得分:5)

看起来你正在混合制表符和空格。使用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()

另见PEP-8 indentation paragraph