我在这个代码中的错误在哪里仍然是个乞丐
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:我错在哪里?
发布于 2019-10-18 10:21:18
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这里的代码运行,我在本地测试了它。
建议:
indenting.
while game_running
while game_running == True
有问题就足够了,您不必显式地编写while game_running == True)。
https://stackoverflow.com/questions/58448525
复制相似问题