Event Probability
Source: Dec 2023, Task 1 (DTU 02002/02003). Study solution — not an official answer key.
Problem
Probability that an event with return period T occurs within n years:
P = 1 - (1 - 1/T)n
Write event_probability(T, n) returning that float.
Example
>>> event_probability(100, 25)
0.22217864060085335
Approach
Implement the formula directly with float division.
Solution
Show solution Hide solution
Solution
def event_probability(T, n):
return 1 - (1 - 1 / T) ** n