IndentationError:打印时需要一个缩进块

问题描述 投票:0回答:1

当我在 python 中打印内容时,我总是遇到缩进错误

inp = input('You are at crossways, where do you want to go? type "left" or "right"')
if inp is 'left':
print("You didn't die. Do you want to wait for a ship or wait for a boat or swim ? Type swim or boat or ship ")

顺便说一句,我正在做游戏 错误我在单词“swim”中的字母 w 处得到错误

<- the error

python indentation
1个回答
0
投票

好的,你写的代码是……

inp = input('You are at crossways, where do you want to go? type "left" or "right"')
if inp is 'left':
print("Luckily you didn't die. Do you want to wait for a ship or wait for a boat or swim ? Type swim or boat or ship ")

固定代码应该是这样的

inp = input('You are at crossways, where do you want to go? type "left" or "right" \n')
if inp == 'left':
  print("You didn't die. Do you want to wait for a ship or wait for a boat or swim ? Type swim or boat or ship ")

我把

if inp is 'left'
改成了
if inp == 'left'
我还在 if 语句之后缩进了打印,因为这可能是错误的原因。

我希望这修复了错误:D

© www.soinside.com 2019 - 2024. All rights reserved.