IndentationError: unindent does not match any outer indentation level error is if player['health'] <= 0:

IndentationError: unindent does not match any outer indentation level error is if player['health'] <= 0:

我这段代码哪里出错了还是初学者

player = {'name': 'Frankie', 'attack': 10, 'heal': 5, 'health': 200}
eliza = {'name': 'Eliza', 'attack': 5, 'health': 200}
game_running = True

while game_running == True:

    print('please select action')
    print('1) Attack')
    print('2) Heal')

    player_choice = input()

    if player_choice == '1':
        eliza['health'] = eliza['health'] - player['attack']
        player['health'] = player['health'] - eliza['attack']
        print(eliza['health'])
        print(player['health'])


    elif player_choice == "2":
        print('Heal player')
    else:
        print('Invalid Input')

     if player['health'] <= 0:
         game_running = False

我的问题是如果玩家['health'] <= 0:我哪里错了

player = {'name': 'Frankie', 'attack': 10, 'heal': 5, 'health': 200}
eliza = {'name': 'Eliza', 'attack': 5, 'health': 200}
game_running = True

while game_running == True:

    print('please select action')
    print('1) Attack')
    print('2) Heal')

    player_choice = input()

    if player_choice == '1':
        eliza['health'] = eliza['health'] - player['attack']
        player['health'] = player['health'] - eliza['attack']
        print(eliza['health'])
        print(player['health'])


    elif player_choice == "2":
        print('Heal player')
    else:
        print('Invalid Input')

    if player['health'] <= 0:
        game_running = False

这里代码运行,我在本地测试过

建议:

  1. 使用 PyCharm 或其他相关 IDE 以便您可以习惯并在 运行 脚本之前有一个概览(在 PyCharm 您会得到一条红线,告诉您缩进有问题。

  2. while game_running 就足够了,你不必明确地写 while game_running == True