mardi 27 juin 2017

Python if-condition isn't working properly, why?

I'm kinda new to python, and I decided to test myself and make an advanced text adventure (with dice rolling and multiple paths etc). I made a function that takes in the three statistics that your character has (intelligence, luck, dexterity) and creates a tailored dice roll for you to conquer:

   def rollCode(a, b, c):
      global inp
      inp = str(randrange(1, 20, 1))
      textCode('You\'ve rolled... %s!\n' %inp)
      if inp < 20 - int(a) - int(b) - int(c):
        textCode('Unfortunately, since %s is less than 20 - ' %inp)
        textCode('%s - ' %intl)
        textCode('%s, you\'ve failed the test, you lose one persistence and try        again!\n' %luc)
        per = per - 1
        if per < 1:
            sys.exit('You died... Rerun the code to start again!\n')
        rollCode(a, b, c)
      elif inp > 20 - int(a) - int(b) - int(c):
        textCode('Fortunately, since %s is more than 20 - ' %inp)
        textCode('%s - ' %intl)
        textCode('%s, you\'ve passed the test!\n' %luc)
        time.sleep(1)

My problem is that, whatever I rolled, python thinks I succeeded the roll (by rolling higher than 20 - a - b - c). I tried everything to fix this, from taking it out from the def-function to completely rewriting the code, but nothing worked. So I'm pretty desperate for help. My exact question is WHY does python not recognize my if-condition and HOW to fix my code! Thank you so mutch for your help!

BTW the textCode function types text char by char in the terminal...

Aucun commentaire:

Enregistrer un commentaire