1

How would I go about to get this to work? I've searched but I can't get it to work still. Should I just put the a() function in the b function even if I add more variables?

counter = 1

def a():
    az = 1
    bz = 2
    cz = 3

def b():
    a()
    if counter > 0 :
        print az, bz, cz

b()
hsel
  • 163
  • 1
  • 7

2 Answers2

1

Alright, you need to understand the concept of scope. az, bz and cz are known only inside your function a(). So you can't print their values inside function b(). You could do something like:

counter = 1

def a():
    az = 1
    bz = 2
    cz = 3
    if counter > 0 :
        print az, bz, cz

def b():
    a()

b()

And as @fileyfood500 said in his comment, you might want to read this.

Community
  • 1
  • 1
rbock
  • 625
  • 5
  • 15
0

One potential fix is to return the values from a.

counter = 1

def a():
    az = 1
    bz = 2
    cz = 3
    return(az,bz,cz)

def b():
    (az,bz,cz) = a()
    if counter > 0 :
        print az, bz, cz

b()
fileyfood500
  • 1,199
  • 1
  • 13
  • 29