Population dynamics 7

functions with optional parameters

Sometimes the input from exercise 6 is not always provided with a comma as a separator. To allow for the option to input the data in a different way, modify the script from exercise 6 by adding an optional parameter for the separator. The output of the script should be the same as in exercise 6.

Assignment

Schrijf een Python-script dat de volgende functionaliteiten bevat.

  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. Then, enhance the function from exercise 6 with an optional input parameter for the separator. If this parameter is not provided, use a comma (“,”) as the default value.
  3. Ensure that the strings are also converted to integers and floats as needed.
  4. Create a new variable ‘name’ that contains the population name and remove the name from the list.
  5. Add the following two elements to the list:

    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}}\]
  6. 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]

Example

  >>> complete_list_with_max_timepoint(elephants-7806-0.039-50000","-")
  > Data elephants: [7806, 0.039, 50000, 162, 49517]
  >>> complete_list_with_max_timepoint(giraffes,5603,0.026,6000")
  > Data giraffes: [5603, 0.026, 6000, 179, 5995]
  >>> complete_list_with_max_timepoint("Lions%5003%0.030%10000", "%")
  > Data lions: [5003, 0.03, 10000, 176, 9949]