Septic Septic - 26 days ago 10
Python Question

Text based game

"#TextBasedGame

import random
import time

attackers=random.randint(0,100)
val1=random.randint(0,1)

health=100
bear=100

name=input("What is your name hero? ")
print("Okay ",name," i need to teach you the basics of combat")
time.sleep (1)
print ("Bear spawns")

if val1==0:
print ("Bear attacks -25 HP")
health=health -25

print ("Health = 75")


attack=int(input("Press 1 to attack "))

if attack==1:
print ("Bears HP -25")
bear = bear -25
else:
print ("Why didn't you attack?!?!?")

if bear==100:
print ("Bear =100")
else:
print ("Bear =75")"


If anyone could help me not do each health part and make it print it after every battle / attack that'd help. Please don't make it too complex this is my homework for school and i only started a few weeks ago.

Answer

You had a lot of mistakes in your code.You did not decrease the health properly and also you need to put the health in a continuous loop so that the game continues until someone dies. Here's the corrected code:

import random
import time

attackers=random.randint(0,100)
val1=random.randint(0,1)

health=100
bear=100

name=input("What is your name hero? ")
print("Okay ",name," i need to teach you the basics of combat")
time.sleep (1)
print ("Bear spawns")
while((health or bear) > 0):
    if val1==0:
        print ("Bear attacks -25 HP")
        health -= 25
        print("Health = ", health)


    attack=int(input("Press 1 to attack "))

    if attack==1:
        print ("Bears HP -25")
        bear -= 25
        print("Bears HP = ", bear)
    else:
        print ("Why didn't you attack?!?!?")

else:
    if health < bear:
        print("You lost!")
    else:
        print("You won!")