-1

Ok so here is the question and feel free to edit it in your way. I just want to know why the if statement after getting input in inp_fg is not working. The program just ends itself after inputting the inp_fg

def fight():
    n = 1
    ph = stats.user_hp      #you can use your own integer values in place of stats.var
    pa = stats.user_att
    pd = stats.user_df
    psta = stats.user_sta
    if n == 1:
        eh = goblin.health  #you can use your own integer values in place of .var
        ea = goblin.attack
        ed = goblin.defence

    def actions():
        print("Options:\nEnter 1 to attack\nEnter 1 to run away(costs stamina)")
        inp_fg = input()

        if inp_fg == 1:
            print("ab")
            p_ac = random.randit(1, 5)
            e_ac = random.randit(1, 5)
            eh = eh - p_ac
            ph = ph - e_ac
            if eh > 0:
                actions()     # i want if the hp of goblin is greater than 0 then it will start the actions() again
            elif eh <= 0:
                print("You won") 
            elif ph == 0:
                print("You died")
    actions()
nfgl
  • 2,812
  • 6
  • 16

1 Answers1

0

You are not casting your input to an integer, so it is the character '1' that you get, and not the number 1. ASCII code for '1' being 49 and not 1, your condition always evaluates to false.

inp_fg = int(input()) does the work.

vultkayn
  • 189
  • 1
  • 8