0

I have a problem with the code below, where I am trying to change the value of the Mode variable. How would i be able to set it accordingly so that I dont get the error: UnboundLocalError: local variable 'Mode' referenced before assignment. I dont want to use a global variable for Mode is there another way I could do this?

from random import randint

Mode = 0 

def Exec_mode(Number, Mode):
    if Number % 2 ==0 and Mode== 2:
        return True
    elif Mode ==0:
        return False

def values(n, Number):
    if Number > 10 and Exec_mode(Number, Mode):
        print("Number: {} is divisible by 2 and greater than 10".format(Number))
        Mode= 1
    elif Number < 13 and Exec_mode(Number,Mode):
        print("Number: {} is divisble by 2 and lower than 8".format(Number))
        Mode =2 

def Number():
    value = randint(0, 1000)
    return value

for n in range(23):
    var = Number()
    values(n,var)
ege Selcuk
  • 227
  • 2
  • 9

0 Answers0