IndentationError:unindent不匹配任何外部缩进级别错误,如果玩家['health'] <= 0:

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

此代码中我的错误在哪里仍然是一个开始

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

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

python-3.x indentation
1个回答
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

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