I have spent the last few hours reading around on the net and looking at the Python online manual (currently using Python v2.7) but I'm still struggling to understand how I pass a variable from one function to another.
At the moment I am just starting out with something simple, to get my head around passing variables. I have 3 functions (one which will display a hello message), another that will ask for user input and the third that will take the user input and perform the calculation).
For the life of me I cant figure how to get the user input values into the calculation function. I thought that once I entered the values in the user input, I could send them to the calc function. But I cant.......I keep getting an error message: calc = calculation(num1, num2) NameError: global name 'num1' is not defined
Can someone point out where I am going wrong ? This is driving me nuts !
def main():
message()
input = user()
calc = cal(num1, num2)
def message():
print "Welcome message"
def user():
side_a = int(raw_input("Enter a: "))
side_b = int(raw_input("Enter b: "))
return side_a, side_b
def cal(num1, num2):
side_c = side_a + side_b
return side_c