Can anyone identify the bug in my code?

This is day 28 of the 100 days of code.

I know there is a bug because sometimes immediately after a tie roll one of the characters dies, this shouldn’t be possible.

Can anyone identify the bug?

import random, os, time

def rollDice(side):
  result = random.randint(1,side)
  return result

def health():
  healthStat = ((rollDice(6)*rollDice(12))/2)+10
  return healthStat

def strength():
  strengthStat = ((rollDice(6)*rollDice(8))/2)+12
  return strengthStat


print("⚔️ BATTLE TIME ⚔️")
print()
name1 = input("Name your Legend:\n")
type1 = input("Character Type (Human, Elf, Wizard, Orc):\n")
print()
print(name1)
health1 = health() 
print("HEALTH:", health1)
strength1 = strength() 
print("STRENGTH:", strength1)
print()
print("Who will your hero battle?")
print()
name2 = input("Name your Legend:\n")
type2 = input("Character Type (Human, Elf, Wizard, Orc):\n")
print()
print(name2)
health2 = health() 
print("HEALTH:", health2)
strength2 = strength() 
print("STRENGTH:", strength2)
print()
print("⚔️ Let's get ready to rumble! ⚔️")
print()
time.sleep(3)
os.system("clear")


if strength1 > strength2: 
  strength_diff = (strength1 - strength2) + 1
elif strength1 < strength2: 
  strength_diff = (strength2 - strength1) + 1
else: 
  strength_diff = 1

deaths = 0

while deaths == 0: 
  p1_roll = rollDice(6)
  p2_roll = rollDice(6)
  if p1_roll > p2_roll:
    print(name1, "attacks,", name2, "dealing", strength_diff, "points of damage\n")
    health2 -= strength_diff 
    time.sleep(1)
    if health1 <= 0 or health2 <= 0:
      deaths = 1 
  if p2_roll > p1_roll:
    print(name2, "attacks", name1, "dealing", strength_diff, "points of damage\n")
    health1 -= strength_diff
    time.sleep(1)
    if health1 <= 0 or health2 <= 0:
      deaths = 1 
  else:
    print("It's a tie, re-rolling!\n")
    time.sleep(1)

if health1 <=0:
  print(name1, "lost!")
  time.sleep(1)
elif health2 <= 0: 
  print(name2, "lost!")
  time.sleep(1)
else: 
  print("Uh oh, we fucked up some how!")
  time.sleep(5)

time.sleep(1)
os.system("clear")

3 posts were merged into an existing topic: Day 028 - Project 28 : Battle Time