# FUNCTION OUTPUTS

In the FUNCTION INPUTS concept, we talked about how functions can take inputs (called parameters) to allow them to do customized tasks. But, not only can functions take inputs, they can also send information back (return output) to other parts of the code. A good example of this is when we have a function that does some calculations for us, and we want to get the results of those calculations.

Perhaps instead of printing the name and birth year of people, we'd rather know how old the person will be on their birthday this year. Using the information we already have from our previous lesson, this calculation is pretty simple – we just subtract the birth year from the current year (2015 as of this writing) and we'll get the age they will be turning this year.

To create a new function to do this, we can still pass in the "birth_year" parameter for the person's birth year (like we did in the previous project) but, instead of printing the information, we do our age calculation and store the resulting value in a new variable called "age".

This is what the function would look like:

def calculate_age(birth_year): age = 2015 - birth_year

Note: When calling this function, it is required that the "birth_year" parameter is a number and not a string so that we can use it to perform this calculation.

Now, to send the information we've calculated back to the main program, we end the function with a return statement that contains the information we're sending back (in this case, we're sending the information contained in the variable, "age"):

def calculate_age(birth_year): age = 2015 - birth_year return age

The value of "age" would then be returned to where the function was called and that value could be stored in another variable, printed or used however it is needed.

For example, we could call this function for Bob and Susie like we did in the last project, but this time, we could get their age as well, store it in a variable and then print it out:

bob_age = calculate_age(2005) susie_age = calculate_age(1999) print('This year, Bob will be ', bob_age) print('This year, Susie will be ', susie_age)

Here is what the entire program would look like:

def calculate_age(birth_year): age = 2015 - birth_year return age bob_age = calculate_age(2005) susie_age = calculate_age(1999) print('This year, Bob will be ', bob_age) print('This year, Susie will be ', susie_age)

There's only one more function concept you need to be familiar with before jumping back into the projects: USING FUNCTIONS & MODULES.