Function Calling

We have two functions set up at the top of our code from the previous lesson. We have been calling them both from the main programming thread:

error_message()

additionTotal = addition(3, 5, True)

But in Python, as in most other programming languages, you can call one function from inside another one. For example, we can call the error_message function from the addition function. You call it in the normal way: just use its name:

def addition(first_number, second_number, add_ten=False):

if first_number == 0:

error_message()

exit()

 

if add_ten is True:

answer = first_number + second_number + 10

else:

answer = first_number + second_number

return answer

Here, we've added an If Statement to check the value of first_number. If it's zero, then we call the error_message function and exit the program.

We'll discuss one more thing about functions, before we move on, and that's scope.

Function Scope >