-1

I just create the function (Python) and want to use the variable that was defined outside the function and an error has occurred

def outside_variable_show(status):
    if status == 1:
        crrnt_nmbr = crrnt_nmbr + 1
        print (crrnt_nmbr)

status = 1
crrnt_nmbr = 0
print (crrnt_nmbr)
outside_variable_show(1)

note: "crrnt_nmbr" must use in and outside the function.

please tell me the way to implementation with it. Thank you so much.

Capmu
  • 35
  • 6

1 Answers1

0

Try this:

def outside_variable_show(status):
    global crrnt_nmbr
    if status == 1:
        crrnt_nmbr = crrnt_nmbr + 1
        print (crrnt_nmbr)

status = 1
crrnt_nmbr = 0
print (crrnt_nmbr)
outside_variable_show(1)
CC7052
  • 563
  • 5
  • 16