# Functions

Since you wrote your first program you have been using functions, defining them using the def keyword.

As your programs get more complex, you will need several functions within one program. This means you will start your program by calling one function, which then will call other functions. This will make your programs well-structured.

For example, you can draw the structure of your program in a chart:

Written as a program this would look like this:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 def input_data(): pass def process_data(): pass def output_data(): pass def main(): #this function calls the other functions input_data() process_data() output_data() 

However, life isn't as simple as it looks here. If you input data in the input data function, you need to pass it into the process_data function. Once you have processed it you need to return it. Then you need to pass the processed data into the outputInfo function so that it can be displayed.

This can be done in programming using parameters. This is described in the next page.

by Sue Sentance.
20 June 2011.
updated on 03 September 2014.