0

我在该行的冒号后得到“预期的标识块”:def StartGame(用户名):该行的其余部分出现红色,并且是编程新手,我不确定我做错了什么。提前谢谢你:)

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 回答 1

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 缩进段落

于 2013-09-14T21:11:28.913 回答