population dynamics 6

lists en tuples

Assignment

Write a Python script that contains 2 functions.

Write a function complete_list_with_max_timepoint that converts a string into a list and further extends this list.

  1. The function takes a string as an input argument:

    ““populationName, initialSize, growthRate, carryingCapacity”

    This string is converted by the function into a list in the following format:

    [populationName, InitialSize, growthRate, carryingCapacity]

  2. Ensure that the strings are also converted to integers and floats as needed.
  3. Create a new variable ‘name’ that contains the population name and remove the name from the list.
  4. Add the following two elements to the list, using a second function calculate_time_to_percentage_carryingCapacity:

    a. The time point at which 99% of the carrying capacity is reached

    b. The corresponding number

Assumption: The population experiences limited growth.

\[N_t = \frac{K}{1 + (\frac{K}{N_0}-1)* e^{-r*t}}\]
  1. The function returns the name and the list of values. Print this in a sentence as well.

Data elephants: [7806, 0.039, 50000, 162, 49517]

Examples

  >>> complete_list_with_max_timepoint('elephants,7608,0.039,50000')
  > Data elephants: [7806, 0.039, 50000, 162, 49502]
  >>> complete_list_with_max_timepoint('Giraffes,5603,0.026,6000')
  > Data giraffes: [5603, 0.026, 6000, 75, 5940]
  >>> complete_list_with_max_timepoint('lions,5003,0.030,10000')
  > Data lions: [5003, 0.03, 10000, 154, 9902]