This is a much-simplified version of my program but has the same idea:
def calc():
x=1
y=2
z=6
def output():
final=x+y+z
how can I use the return values in the first function to be used in the second?
This is a much-simplified version of my program but has the same idea:
def calc():
x=1
y=2
z=6
def output():
final=x+y+z
how can I use the return values in the first function to be used in the second?
The method calc
must return the values to allow output
to retrieve them when calling it.
I deliberately changed the name of the variables in the output
method, so you see, they are not related and can be named as you want.
def calc():
x = 1
y = 2
z = 6
return x, y, z
def output():
a, b, c = calc()
final = a + b + c
print(final) # 9
if __name__ == '__main__':
output()
def calc():
x=1
y=2
z=6
return x + y + z # you need to use 'return' in order for function to return some values
def output():
final = calc()
or
def calc():
x=1
y=2
z=6
return x, y, z # you need to use 'return' in order for function to return some values
def output():
x, y, z = calc()
final = x + y + z
Yet another option:
def calc():
x=1
y=2
z=6
return x, y, z
def output(values):
x, y, z = values
final = x + y + z
return final
print(output(calc()))