5. Functions#

In previous chapters, in every worked exercise, we discussed how to solve a problem by decomposing the solution into steps. Sometimes, we decompose the problem into smaller sub-problems that can be decomposed into further steps. In this chapter, we will discuss how to write a sequence of instructions as a function to consider it as a step by itself. We will discuss how to use functions for a sub-problem to solve “the” problem.

Think of assembling a table. It is difficult to think of building the table from scratch. You bought the table not assembled and you were given instructions on how to assemble it. We can think of each step in the assembling manual as a function.