Hi, I know the general idea behind nested functions, and how one function can call another inside it. But this example, from Python, confuses me a bit. One function totalPct, is called using a startValue and years. But how can makeTotalPct return totalPct (in the form of pctIncrease) if no pct value was provided anywhere? I only gave startValue and years, but no pct.
def pctIncrease(begin, end):
def increaseByPct(begin, pct):
def makeTotalPct(startValue, years):
value = startValue
for year in range(years):
value = increaseByPct(value, pct)
return pctIncrease(startValue, value)
totalPct = makeTotalPct(175.1, 5)
totalPct2 = makeTotalPct(154.4, 10)
Also, why do I not write "return totalPct()" instead of "return "totalPct"? Aren't I calling the function, which would give me the return value? I greatly appreciate any help.