Basic health system with 'health-boost drink'

Viewed 21

My text based game needs a health system with a maximum of 100 health, but the program begins at 80 health.

The user can also use a drink at any stage during the program, which adds 30 health to the player.

How do I let the user input 'drink' at any point during the entire program while keeping the health under or equal to 100, and being able to continue running the code?

health = 80
drink = 1

def drinkfunc():
  decision = input('a, b, c or drink?\n').lower()
  if decision.lower() == 'drink':
    global drink
    global health
    while drink > 0 and health > 0 and health < 101:
      if health > 70:
        while True:
          drink = 0
          health = health + 1
          if health == 100:
            print(f'Health: {health}')
      elif health < 71:
        health = health + 30
        print(f'Health: {health}')
      else:
        break
0 Answers
Related