Interview Query

Rain in N Days

3
Have you seen this question before?

The probability that it will rain tomorrow is dependent on whether or not it is raining today and whether or not it rained yesterday.

If it rained yesterday and today, there is a 20% chance it will rain tomorrow. If it rained one of the days, there is a 60% chance it will rain tomorrow. If it rained neither today nor yesterday, there is a 20% chance it will rain tomorrow.

Given that it is raining today and that it rained yesterday, write a function rain_days to calculate the probability that it will rain on the nth day after today.

Example:

Input:

n=5

Output:

def rain_days(n) -> 0.39968
Next question: Market Opening Experiment
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code