where is my error in this code still a begginer
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
my issue is this if player['health'] <= 0: where am i wrong
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
The code here runs, I tested it locally.
Suggestions:
Use PyCharm or other related IDE so that you can get accustomed and have an overview before running the script (in PyCharm you would get a red line telling you that there is a problem with indenting.
while game_running
is sufficient, you do not have to explicitly write while game_running == True