【问题标题】:Indentation error: expected an indented block ,in python [closed]缩进错误:在python中需要一个缩进块[关闭]
【发布时间】:2020-03-31 19:45:41
【问题描述】:

最近开始学习使用 python,我正在尝试制作一个基本的基于文​​本的游戏,我遇到了一个函数定义的小问题,它说 elif 语句存在缩进错误 (elif hit_c == 1),(还要注意我已经导入了所有需要的库并在函数中定义了所有变量)

def damage(x):
    """ This function will determine the amount of damage you will take """
    """ hit_c is the chance the enemy has to hit you """
    global User_HP
    global Enemy_HP

    hit_c = randint(1,5)
    User_damage = randint(1,4)

    if hit_c >= 2:
        Enemy_HP -= User_damage
        print(f"You dealt {User_damage} damage!")
        print(Enemy_HP)
        if Enemy_HP < 0:

    elif hit_c == 1:
        print("You missed!")

    hit_c = randint(1,5)
    Enemy_damage = randint(1,3)

    if hit_c >= 2:
        User_HP -= Enemy_damage
        print(f"You took {Enemy_damage} damage!")
        print(User_HP)

我没有看到我的函数中的缩进有任何问题,并且不确定为什么这个语句特别是有错误。非常感谢您的帮助!

【问题讨论】:

  • if Enemy_HP &lt; 0: 逻辑中缺少结果

标签: python indentation function-definition


【解决方案1】:

问题出在这里:

    if Enemy_HP < 0:

elif hit_c == 1:

您忘记在第一行完成if 语句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-16
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    相关资源
    最近更新 更多