While loop won't update variables with each repeat

580 views python
8

I'm trying to make a text game where with each pass, your decisions change your health, but it just isn't working. I'm not getting any errors, but the code isn't behaving

link to the code on repl.it

^ Is the code. Can anyone help me get the variables to update after each pass through the code so that when you choose an action, it updates for the next round?

answered question

input returns a string ... so compare action=="1"

3 Answers

4

You should convert the action from the user input into an integer if you want to compare it with other integers:

action = int(input("Shall you (1)haunt (2)steal (3)practice."))

posted this
11

action is a string not an integer. Change your code to something like this:

if action == '1':
    spook -= 1
    health += 1

posted this
1

You code takes input which is interpreted as a string. But when you test the values being supplied, you test them as integers.

1 != '1'

if action == '1':
    spook -= 1
    health += 1

  if action == '2':
    health -= 1
    candy += 1

  if action == '3':
    candy -= 1
    spook += 1

posted this

Have an answer?

JD

Please login first before posting an answer.