TurnBased TextFighter:缩进E

2024-09-19 23:27:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个Python新手。你知道吗

我的代码的if语句周围不断出现缩进错误。 if/else语句的第一块可以读取。 第二个块导致缩进错误。 当我移除它进行调试时。 第三个块(在末尾)也返回缩进错误。 …但我不知道在哪里能找到他们?你知道吗

对出了什么问题有什么建议吗?你知道吗

# 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!")

Tags: anddebugif错误ending语句elsehp
3条回答

假设您尝试运行发布的代码,问题是在您第一个“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语句的注释。 希望有帮助。你知道吗

不是引号。我在将代码传输到stackoverflow时犯了这个错误(为了可读性/紧凑性修改了代码)。你知道吗

错误在于某些else语句的注释。 Python从不读取/执行任何内容,所以它只假设后面的内容应该是缩进的。你知道吗

一旦我把通行证放在else语句下面,一切就都清楚了。你知道吗

你好像忘了双引号

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

文本的颜色本可以帮助您;)

相关问题 更多 >