Looks like you're using random.randint , not sure if it's the same as python but i made a little text game so i'll just copy past the combat here if it helps.
At start of adventure
player_hp = 20
inventory = []
Combat:
def boss_fight():
global player_hp
boss_hp = 30
print(f"The fight begins! You have {player_hp}HP, the creature has {boss_hp}HP")
while player_hp > 0 and boss_hp > 0:
print("\n Your turn:")
print("1. Attack the creature!")
print("Use a healing potion (if you have one)")
choice = input("What do you do >> ")
if choice == "1":
player_attack = random.randint(4,8)
print(f"You strike at the creature dealing {player_attack} damage!")
boss_hp -= player_attack
elif choice == "2" and "healing potion" in inventory:
player_hp += 10
player_hp = min(player_hp, 20)
print(f"You use the healing potion and recover 10hp. You now have {player_hp}hp.")
inventory.remove("healing potion")
elif choice == "2" and "healing potion" not in inventory:
print("You do not have a health potion.")
continue
else:
print("Now is not the time to waver!")
continue
if boss_hp <= 0:
print("With a final blow the creature falls to the ground, and the dungeon fall silent.")
print("Congratulation! You have slain the creature and saved the people from it's evil!")
return
boss_attack = random.randint(3,6)
print(f"The creature strikes you with dark fury dealing {boss_attack} damage!")
player_hp -= boss_attack
print(f"You have {player_hp}hp left.")
if player_hp <= 0:
print("You fall, slain. The creatures dark malice spreads from the dungeon, coating the world in darkness and blotting out the sun.")
print("You failed to slay the creature and fell in combat. Game Over...")
return
print(f"Your HP: {player_hp} | Creature's HP: {boss_hp}")
print("/nThe battle ends.")