此代码中我的错误在哪里仍然是一个开始
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:我在哪里错了
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
这里的代码运行,我在本地进行了测试。
建议:
使用PyCharm或其他相关的IDE,以便您可以习惯并在运行脚本之前获得概述(在PyCharm中,您会看到一条红线,告诉您缩进存在问题。
while game_running
就足够了,您不必显式编写while game_running == True