A function is a collection of statements that accept input, perform some specific computation, and return output. The idea is…