0

Basically I have this section of code that goes like so:

def start():

def blockA():
    y = 3
    x = 4
    print("hello")
blockA()

def blockB():
    if x !=y:
        print("not the same")
blockB()
start()

However, this gives me an error saying that x and y are not defined. How would I go about referencing the x and y variables in blockB?

1 Answers1

1

You need to return the variables in blockA function and call that function in your second function.

def blockA():
    y = 3
    x = 4
    print("hello")
    return x,y


def blockB():
    x,y=blockA()
    if x !=y:
        print("not the same")

This should work for you.

Ankur Gulati
  • 291
  • 1
  • 12