-1

If i'm not very clear let my explain I have this code -

health = {
    'Health': 10,
    'Enemy Health': 3
    }
import random
variable = random.choice([1 , 2 , 1])   
print "Attack/Flee"

turn1 = True
turn2 = False

while turn1:
    A = raw_input()
if A == "Attack" or "attack":
print health['Enemy Health'] - variable

what i'm trying to achieve is a turn based attack system, when the player attacks the variable actually changes. like this

Attack/Flee
1
Attack/flee
0
Attack/flee
-2

I'm trying to make this turn based as well so the enemy can also attack

mido
  • 24,198
  • 15
  • 92
  • 117
Jack
  • 3
  • 1
  • `health['Enemy Health'] =health['Enemy Health'] - variable` you just set the variable ... Im not sure what your stuck on ... – Joran Beasley Dec 01 '15 at 20:48
  • 3
    A *constant* is something that does not change. I guess you wanted to say something else? Anyway, to change value of `health['Enemy Health']`, you do: `health['Enemy Health'] = new_value` – zvone Dec 01 '15 at 20:49
  • Why do you want `variable` to be a variable? Why not a function? – user2357112 Dec 01 '15 at 20:51
  • 1
    Unrelated to your current problem, but `if A == "Attack" or "attack":` doesn't do what you think. See [Why does `a == b or c or d` always evaluate to True? \[duplicate\]](http://stackoverflow.com/q/20002503/953482) for more information. – Kevin Dec 01 '15 at 21:07

1 Answers1

0

You are not changing the variable enemy health

if you do

while turn1:
    print constant - random

your constant will remain the same, what you have to do if you dont want to change the constant, is creating another variable like this

enemy_life = health['Enemy Health']
    while turn1:
        A = raw_input()
        if A == "Attack" or "attack":
        enemy_life = enemy_life - variable
        print enemy_life

and if you want your wile to end after the "enemy_life" reaches 0 then:

    enemy_life = health['Enemy Health']
    while (enemy_life>0):
        A = raw_input()
        if A == "Attack" or "attack":
        enemy_life = enemy_life - variable
        print enemy_life