python-3.x - “预期有缩进块”错误,但有一个缩进块
问题描述
我收到语法“预期有缩进块”错误,但那里肯定有一个缩进块。我已经检查并重写了一百万次。
#Game loop:
while True: #The error is occurring here
load()
#Main game loop:
while game_over == False:
load_stage()
#Win screen and restart option:
print('\n**********************************************')
print ('Congratulations! You Won!')
answer = input('Would you like to restart?\nIf so type \'restart\'.')
if answer == 'restart':
restart()
save()
else:
pass
解决方案
尝试:
#Game loop:
while True: #The error is occurring here
load()
#Main game loop:
while game_over == False:
load_stage()
#Win screen and restart option:
print('\n**********************************************')
print ('Congratulations! You Won!')
answer = input('Would you like to restart?\nIf so type \'restart\'.')
if answer == 'restart':
restart()
save()
错误出现是由于缩进不一致,这意味着您的程序没有一致的缩进方案。一般来说,建议使用 4 个空格(其中空格 = 单个空格键)来表示缩进块。
如果您的程序交替使用 Tab 和空格进行缩进,也会出现不一致的情况。
推荐阅读
- sockets - Windows 10 iot 核心 (rpi3) 上的套接字通信
- javascript - Html 有没有办法将 concat 从桌面发送到手机?
- kubernetes - Kubernetes pod 回滚和重启
- rest - Microsoft Graph API - 访问邮件时出现 AuthenticationError
- winforms - GreatMaps (GMap.net) 离线文件...要下载吗?
- c++ - C++ 中的素数生成器(alex alllain 跳入 C++)
- react-native - 返回时屏幕状态未从 AsyncStorage 更新
- amazon-web-services - 在 ubuntu 18 上找不到请求的 URL
- python - 在Django中查询一对多关系然后聚合
- reactjs - 如何使用反应钩子仅展开和折叠手风琴中的第一项?