回合制文本格斗:缩进错误

Turn-Based Text-Fighter: Indent Error

我是Python新手

我的代码的 if 语句周围总是出现缩进错误。 if/else 语句的第一块读得很好。 第二个块导致缩进错误。 当我删除它进行调试时。 第三块(最后)也 returns 缩进错误。 ...但我不确定在哪里可以找到它们?

有什么问题的建议吗?

# Begin Fight/Conditions for Ending
while Player.hp > 0 and Marco.hp > 0:

    while playerchoice not in [1,2,3,4]:
        playerchoice = input("\n Which move would you like to use: ")

    marcochoice = random.choice([1,2,3,4])

    # Making the Moves - Player Always Goes First (For now!)
    if playerchoice == 1:
        Player.jabs(Marco)
        #print("\n Player - jabs - Debug")
    elif playerchoice == 2:
        ...
    else:
        #print("Player - Non-Choice - Debug")

    # Marco's Turn!
    if Marco.hp > 0:
        if marcochoice == 1:
            Marco.jabs(Player)
            #print("Marco - Jabs - Debug")
           ...
        else:
            #print("Marco - Non-Choice - Debug")
    else:
        pass

# Ending Conditional 


if Marco.hp <= 0 and Player.hp <= 0:
    print("It's a draw!")
...
else:
    print("Something has gone horribly wrong!")

你好像忘记了双引号

playerchoice = input("\n Which move would you like to use: ")

文本的颜色可能对您有所帮助 ;)

不是引号。我在将代码传输到 Whosebug 时犯了这个错误(修改了 readability/compactness 的代码)。

错误与一些else语句的注释有关。 Python 从来没有 reads/executes 任何东西,所以它只是假设后面的任何内容都应该缩进。

一旦我将 pass 放在 else 语句下面,一切就都清楚了。

假设您尝试 运行 您发布的确切代码,问题是您第一个 'else:' 语句之后的评论。同样的情况发生在这里:

for i in range(10):
    if i in [0,1,2,3,4,6,7,8,9]:
        print("found")
    else:
        #print("test")
print("that could be it")

为了 运行 没有问题,只需取消注释第二个 print 语句。 希望对您有所帮助。