I need help with the define function


I don’t understand why it won’t take what i’ve said in the main function and use it in the main2?

def main2():
print (number)
def main():
number = 5*6

Help :frowning:


Variables inside functions are scoped to that function, and not the outside world.


Thank you, is there any way to make them carry over?


Make the variable number a global, or return a value from your function (the better option).

def output(n):
    print (n)

def compute(a, b):
    return a * b

output(compute(5, 6))    # 30


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.