一个简单的 Python 程序的缩进
Indentation of a simple Python program
playerA=input("Please choose one from rock paper and scissors")
playerB=input("Please select one from rock paper and scissors")
if playerA=rock and playerB=paper:
print("player B wins")
elif playerA=scissor and playerB=paper:
print("Player A wins, Congratulations Player A. Do you want to play
another game? ")
elif playerA=rock and playerB=rock:
print("game is draw, Do you want to play another game")
elif playerA=paper and playerB=paper:
print("game is draw")
elif playerA=scissor and playerB=scissor:
print("game is draw")
elif playerA=paper and playerB=scissor:
print("Player B wins, Congratulations Player B. Do you want to play another game?")
elif playerA=scissor and playerB=rock:
print("Player B wins, Congratulations Player B. Do you want to play another game?")
elif playerA=rock and playerB= scissor:
print("Player A wins, Congratulations Player A. Do you want to play another game?")
elif playerA=paper and playerB=rock:
print("player A wins, Congratulations Player A. Do you want to play another game?")
请问我应该如何修复这里的缩进,我得到的错误是说
unindent 不匹配任何外部缩进级别。
您是否尝试过在 'if' 之后只输入 space 而不是制表符?
if playerA==rock and playerB==paper:
会变成:
if playerA==rock and playerB==paper:
此外,您的倒数第二个 elif 还有一个 space。删除它也应该有所帮助。
您需要取消所有代码的缩进,然后使用制表符正确缩进。您混用了制表符和 spaces,这就是问题所在。
您还可以使用在 Python 安装的 Tools/scripts/
目录中找到的 reindent.py
脚本。更改 Python (.py) 文件以使用 4-space 缩进并且没有硬制表符。还有 trim 多余的 space 和来自行尾的制表符。还要确保最后一行以换行符结尾。
删除此代码后 elif 之前的空白 space..
`elif playerA=paper and playerB=paper:
打印("game is draw")
elif playerA=scissor 和 playerB=scissor:
打印("game is draw")`
删除 else 语句。像这样
else
only
no statement is required
playerA=input("Please choose one from rock paper and scissors")
playerB=input("Please select one from rock paper and scissors")
if playerA=rock and playerB=paper:
print("player B wins")
elif playerA=scissor and playerB=paper:
print("Player A wins, Congratulations Player A. Do you want to play
another game? ")
elif playerA=rock and playerB=rock:
print("game is draw, Do you want to play another game")
elif playerA=paper and playerB=paper:
print("game is draw")
elif playerA=scissor and playerB=scissor:
print("game is draw")
elif playerA=paper and playerB=scissor:
print("Player B wins, Congratulations Player B. Do you want to play another game?")
elif playerA=scissor and playerB=rock:
print("Player B wins, Congratulations Player B. Do you want to play another game?")
elif playerA=rock and playerB= scissor:
print("Player A wins, Congratulations Player A. Do you want to play another game?")
elif playerA=paper and playerB=rock:
print("player A wins, Congratulations Player A. Do you want to play another game?")
请问我应该如何修复这里的缩进,我得到的错误是说 unindent 不匹配任何外部缩进级别。
您是否尝试过在 'if' 之后只输入 space 而不是制表符?
if playerA==rock and playerB==paper:
会变成:
if playerA==rock and playerB==paper:
此外,您的倒数第二个 elif 还有一个 space。删除它也应该有所帮助。
您需要取消所有代码的缩进,然后使用制表符正确缩进。您混用了制表符和 spaces,这就是问题所在。
您还可以使用在 Python 安装的 Tools/scripts/
目录中找到的 reindent.py
脚本。更改 Python (.py) 文件以使用 4-space 缩进并且没有硬制表符。还有 trim 多余的 space 和来自行尾的制表符。还要确保最后一行以换行符结尾。
删除此代码后 elif 之前的空白 space..
`elif playerA=paper and playerB=paper: 打印("game is draw")
elif playerA=scissor 和 playerB=scissor: 打印("game is draw")`
删除 else 语句。像这样
else only no statement is required