mardi 23 novembre 2021

How to use correctly global variables inside if/elif conditions (python)?

I have this code: When i change the variables value it gives me NameError: name 'y' is not defined How can I solve?

def a():

    if 5 == 5:
    
       global x
       x = 39
       return True

    elif 6 == 6:

       global y 
       y = 3 
       return True




def b():


    if x == 3:
        print("ok")

    elif y == 3:
        print("no")
    
a()
b()

Aucun commentaire:

Enregistrer un commentaire