Insect Population Control T86921


Statement
 

pdf   zip   main.py

thehtml

Field biologists run a field experiment over n days to assess the population of an invasor insect species.

An insect trap is set on the first day, and a new trap is added every day, so on the ith day, i traps are deployed. Each trap is expected to capture K individuals. However, specimens learn to avoid traps, so the effectiveness of the traps decays with time.

For this, the expected number of captured individuals on the i-th day is:

Ei = 
K*i
i!

Thus, the accumulated number of captures after n days of field work will be:

C(n) = 
n
i=1
K*i
i!

Write a function captures(n,K) that receives two integers: the number of days of the field experiment (n) and the expected captures per trap (K) and returns the expected accumulated number of captures C(n) at the end of the field experiment.

Observation

  • You are not allowed to import any function from math module.
  • Using lists is not necessary, and will severely penalize your grade.
  • Only the function is expected. If you have a main program to test it, comment it out, or put it inside an if __name__ == "__main__": conditional.
Sample session
>>> captures(4,8)
21.333333
>>> captures(8,3)
8.154762
>>> captures(11,5)
13.591409
>>> captures(21,2)
5.436564
>>> captures(8,3) + captures(11,5)
21.746171
Information
Author
Lluís Padró
Language
English
Official solutions
Python
User solutions
Python