Population dynamics 5

Functions

To make the code more user-friendly, we will use functions. In this assignment, you will convert the written code from assignment 3 into a function that you can reuse.

Assignment

Write a Python script that includes the following functionalities.

  1. Write a function calculate_time_to_percentage_carrying_capacity that calculates the time needed to reach a population size that is a certain percentage of the carrying capacity. Look at how you can use the code from the previous exercises for this. The input for this function is the initial number, the growth rate, the carrying capacity, and the percentage. The output is the time (in years) needed to reach the percentage of the carrying capacity and the number of elephants.

  2. Ask the user to input following values:

  1. Use the entered data as input parameters for the function calculate_time_to_percentage_carrying_capacity. Use 99% and 50% as the percentages.

  2. Print the results as follow:

After x years xx% of the carrying capacity is reached, being xx elephants.

Assumption: The population experiances limited growth.

\[N_t = \frac{K}{1 + (\frac{K}{N_0}-1)* e^{-r*t}}\]

Example

Input

Initial population size:7806
Growth rate:0.039
Carrying capacity:50000

Output

After 162 years 99% of the carrying capacity is reached, being 49517 animals.
After 44 years 50% of hte carrying capacity is reached, being 25357 animals.