Explaining Functions Calling Functions


Hi everybody. I completed this portion, but I am still having trouble understanding what is happening with this code (I want to try to understand the processes associated with this.

This is the code.

1. def one_good_turn(n):
    return n + 1
2. def deserves_another(n):
    return one_good_turn(n) + 2

So from what I understand, the following is happening.

  1. We defined a function.

  2. We defined a second function.

  3. In this second function, we have a call. This second function activates the first function and inputs its result into it.

Does this sound correct or am I missing something?


The second function is dependent upon the first. This is what I like to call a dependency chain.


you can forget calling a function you can add 3


Basically, yeah, the second function in your example is based on calling the first function and adding a thing of its own (+ 2).

If that helps you, I've recently had to write a certain code of a certain article generator. I divided the article generating into three functions — first function generated a headline, second function generated the content, and the third function called first and second function to put an article together. That was helpful because not only it made my code cleaner and easier to read, but also I didn't have to copy the same things like excepts handling to all of the functions but I could just put it in the third one and if an error popped out in 2nd function, it would be handled by 3rd one.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.