Simple Recursion Function
Function Calculator Let's create a logic to calculate the population after y years, given an initial population of n people and an annual growth rate of r%. The logic can be expressed with the following formula: (Population in year y) = (1+r/100)*(Population in year y-1) (Population in year 0) = n In the first line above, the population in year y represents the population we want to know, and the population in year (y-1) means the population of the previous year. Therefore, it means that the population in a given year is the previous year's population increased by r%, or r/100, and this calculation is (1+r/100) * previous year's population. The second line, population in year 0, means the initial population. The above expression can be converted into code that a computer can understand as follows: def population(y,n,r)=(1+r/100)*population(y-1,n,r); population(0,n,r)= n; You can see that only the variable y changes, while the other variables n and r are constants. ...