Q:

python local variable referenced before assignment

variable = "Hello"
def function():
  global variable
  print(variable)
function()
5
"""
This happens when python thinks that your variable is local
(the scope is only within a specific function) and/or that
you have not assigned a value to the variable before in this
specific function (scope).

try:
 - assigning the variable a value within the function
 - Declaring the variable as global (bad practice)
 
Read more about this error in the source
"""
1
print(costPerSeat)
0

New to Communities?

Join the community