我正在尝试制作一个基于快速文本的曲棍球队管理游戏,但每当我参考我的一个功能时,我都会得到"预期的缩进块".不确定我是不是很蠢,也找不到我的错误.
def startup():
print "Welcome to the Text Based Hockey League!"
print "You will be tasked with being a team's General Manager"
yourTeam = raw_input()
class tbhl:
def __init__(self):
self.teamList["Mustangs", "Wolves", "Indians", "Tigers", "Bears", "Eagles", yourTeam]
class game:
def __init__(self, homeScore, awayScore):
#games left in a team class
startup() #<-The line that the error points to
tbhl = tbhl()
print tbhl.teamList[7]
Run Code Online (Sandbox Code Playgroud)
当您将注释掉的块作为函数的唯一代码时,也请使用关键字pass来防止此错误.任何开始新行缩进的代码块都不能留空(或只有注释.)
...
class game:
def __init__(self, homeScore, awayScore):
#games left in a team class
pass
Run Code Online (Sandbox Code Playgroud)
pass 是一个无操作,它会在编译器找到缩进级别的东西时取悦它.