I have been working on this fantasy battle game which is working as expected although the while True loop that starts the game at the very end isn't iterating. I tried using continue with no success. I have included a flow chart to visually show the logic of the game. I'm not getting any error, the loop which should be infinite is just stopping at the end without starting over. Hoe can I make it iterate until it reaches one of the break?
"""
Fantasy Battle Game
Player against Dragon
"""
# Player
wizard = "Wizard"
elf = "Elf"
human = "Human"
# Player health
wizard_hp = 70
elf_hp = 100
human_hp = 150
# Player damage force
wizard_damage = 150
elf_damage = 100
human_damage = 20
# Dragon health and damage force
dragon_hp = 300
dragon_damage = 50
# Print the list of characters
print(wizard)
print(elf)
print(human)
# Input function to choose player
character = input("Choose your character: ")
# While loop to represent player profile
while True:
if character == "Wizard":
my_hp = wizard_hp
my_damage = wizard_damage
break
elif character == "Elf":
my_hp = elf_hp
my_damage = elf_damage
break
elif character == "Human":
my_hp = human_hp
my_dammage = human_damage
break
else:
print("Unknown Character")
break
# Print player selection
print(character)
# print player health:
print(my_hp)
# print player damage force:
print(my_damage)
# Start game
while True:
# Player start first battle against Dragon
dragon_hp = dragon_hp - my_damage
# If dragon health is positive show remaining health
if dragon_hp > 0:
print(f'{character} damaged the dragon!')
print(f'The Dragon hitpoints are now {dragon_hp}')
# If dragon health is negative or null - game over
elif dragon_hp <= 0:
break
print(f'The Dragon lost the battle!')
# Dragon start second battle against player
my_hp = my_hp - dragon_damage
# If player health is positive show remaining health
if my_hp > 0:
print(f'The Dragon strikes back at {character}')
print(f'The {character} hitpoints are now {my_hp}')
# If player health is negative - game over
elif my_hp <= 0:
break
print(f'The {character} lost the battle!')

printstatement before thebreakso you can see when it breaks out.whileloop is totally useless -- it breaks after every branch and so will never actually loop. You might as well remove it. In the second loop, if you want it to run based on some condition, you can put that as the while condition instead ofTrue:while dragon_hp > 0 and my_hp >0