I need help with the define function


#1

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
main()
main2()

Help :frowning:


#2

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


#3

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


#4

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

#5

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