-1

I have problem which cannot fix. I get the error

UnboundLocalError: local variable 'checking' referenced before assignment

My code

    def volume_checker_first_stage(volume1,volume2,withdraw_minimun):
      if volume1>volume2:
       quantity = volume2
       if quantity > withdraw_minimun:
            checking = True
       return quantity, checking
      elif volume2>volume1:
       quantity = volume1
       if quantity > withdraw_minimun:
              checking = True
       return quantity, checking
      else:
       return None,None
Arrmlet
  • 69
  • 2
  • 6
  • `checking` is not defined for the case: `quantity <= withdraw_minimun`. You might want to define `checking = False` in the beginning of your function. – Maurice Meyer Jan 28 '19 at 21:57
  • Possible duplicate of [Python 3: UnboundLocalError: local variable referenced before assignment](https://stackoverflow.com/questions/10851906/python-3-unboundlocalerror-local-variable-referenced-before-assignment) – mad_ Jan 28 '19 at 22:06

2 Answers2

1

Initialize checking to False as the first line in your function to avoid this error.

Powertieke
  • 2,368
  • 1
  • 14
  • 21
1

As the first line of the body of your function, code this:

checking = False

You have a return statement that returns the value of checking, but your code doesn't always set it. Referenced before assignment means your return statement asked for the value of the variable before your code assigned it.

BoarGules
  • 16,440
  • 2
  • 27
  • 44