Function Exercise

Function

A function is a part of a program designed to perform a specific task and is separate from the program that calls it. In creating complex programs with many features, we are required to use functions. Functions are necessary to make it easier to read the code and to maintain it. With a function, we don’t have to write extensive code in the main program; instead, we can break it down and simply call the function within the main program. This also shortens the writing of the main program.

Functions can have parameters that are used to pass variables into a function. When declaring parameters in a function, we can also include default arguments/parameters.

Functions can also return values using the return keyword, placed within the function’s block to return the desired value back to the main program.

MODULE

Download Module 7