python - 我在 python3 中得到 TabError 但在 python2 中没有
问题描述
它在 python2 中工作得很好,但在 python3 中出现此错误-语句“b = b + a”上的“TabError:缩进中制表符和空格的不一致使用”。已经尝试删除空格并检查缩进是否正确。
def dice():
b=0
global a
a=random.randint(1,6)
b=b+a
if(b>22):
b=b-22 #Since 22 blocks in our board, one lap completion will result in
a decrease of 22
#print b
return b
解决方案
在 if 语句和函数定义中,冒号语法后都需要制表符。尝试这个:
def dice():
b=0
global a
a=random.randint(1,6)
b=b+a
if(b>22):
b=b-22 #Since 22 blocks in our board, one lap completion will result in a decrease of 22
#print b
return b
推荐阅读
- javascript - 在javascript中使用正则表达式解析数组语法
- python - 无法使用python在列中打印目录列表
- javascript - Getting a list of exclusive class name with a class name in puppeteer
- sql - 如何获得我的结果为 1 2 3 6 7 8 的列我想从两个表中排除公共 ID 并将结果显示在一个列中
- git - 如何区分 git pull request commit 和 direct checkin commit?
- spring - Spring Web Flow flowExecutionUrl 为空
- angular - Angular 7 - 将 HTTP 请求保存到本地存储
- node.js - express-ws:“ws.send 不是函数”
- android - 如何让其他应用播放/暂停音乐?
- python - Python 子进程类