Sorry for the long code, but I felt that it was important that I include what I was trying to accomplish. I am a beginner with Python and programming in general and I was trying to make a simple text-based adventure game. The game was working good at first until I added the encounter with the bees. I ran the program and I chose to run from the bear, so my hp should be at 40, which was displayed. However, when I chose to swat the bees, my hp should then be at 0 because 40(my current hp)-40=0. My hp is however is displayed at 60, as if the bear encounter never happened. Is there some way I can fix this or is this a limitation in Python?
from sys import exit
from time import sleep
#Hp at start of game:
hp = 100
#The prompt for inputs
prompt = "> "
choice = raw_input("> ")
if "stand" in choice:
print "The bear walks off, and you continue on your way"
elif "run" in choice:
print "The bear chases you and your face gets mauled."
print "You barely make it out alive, however you have sustained serious damage"
hp = hp-60
elif "agressive" in choice:
print "The bear sees you as a threat and attacks you."
print "The bear nearly kills you and you are almost dead"
hp = hp-90
print "Well do something!"
choice = raw_input(prompt)
if "run" in choice:
print "The bee flies away and you continue on your way."
elif "swat" in choice:
print "You succesfully kill the bee. Good Job!"
print "Wait a minute"
print "The bee you killed gives off pheremones, now there are hundreds of bees chasing you."
print "The bees do some serious damage."
hp = hp-40
print "Well, do something."
#Function to display the current hp of the current player
if hp < 100:
print "Your hp is now at %d" % hp
elif hp <= 0:
print "You are still healthy, good job!"
#Called when player dies
print "You sustained too much damage, and as a result have died."
print "GAME OVER!"
print "Would you like to play again?"
choice = raw_input("> ")
if "y" in choice:
#Called to Start the Game, useful for restarting the program
print "Welcome to Survival 101"
#START OF GAME
print "You start your regular trail."
print "It will be just a little different this time though ;)"
print "You are walking along when suddenly."
#Start of first encounter
print "Wild bear appears!."
print "What do you do?"
print "Stand your ground, Run away, be agressive in an attempt to scare the bear"
#Start of second encounter
print "You continue walking and see a killer bee approaching you"
print "What do you do"
print "run away, swat the bee away"
hp to functions and inside a function you are updating it, but you are not getting the updated value
hp back from the function. You should specify
return hp inside the function to return the updated value, and you can store (or update) the updated value in the function call - e.g.,
hp = bear(hp).