GH Python function returning None

python

#1

Hello,
this is a simple mistake since I have not been coding in python recently, but I have simple functions that are printing strings properly. However, when I ask the function to output an integer, a = 5 for example… I get null. I am totally stumped. Thank you.

def biologistScenario():
    if (inhabitants == 1):
        print "now generating a solution for a single Biologist..."
        print True
        a = 5
    elif (inhabitants == 2):
        print "now generating a solution two Biologists..."
    elif (inhabitants == 3):
        print "now generating a solution three Biologists..."
        
def studentScenario():
    if (inhabitants == 1):
        print "now generating a solution for a single Student..."
    elif (inhabitants == 2):
        print "now generating a solution two Students..."
    elif (inhabitants == 3):
        print "now generating a solution three Students..."
        
def main():
    
    if (vocation == 1):
        biologistScenario()
    elif (vocation == 2):
        studentScenario()
main()


(Giulio Piacentino) #2

Hi @brobes05

only module attributes (that is, global variables in the module) are picked up from GhPython. If you assign a = something from a function, you’ll have to specify that you mean the global a before that line.

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#3

Thank you kindly for your response @piac. I saw a thread about the global variable condition, but did not understand completely until your explanation.

I appreciate your help!