Python Puzzles
You die and arrive at the pearly gates of heaven. Unfortunately, the pearly gates are a set of three random doors. One door leads directly to heaven, one door leads to a 2 day stay in purgatory, and one door leads to a 3 day stay in purgatory. Once you are done with your stay in purgatory, you are back again to the pearly gates where the doors are again randomized.
What is the average stay in purgatory?
On average a person will spend 3 days in purgatory.
import random totaltime = [] for _ in range(1_000_000): time = 0 door = random.randint(0,3) while door != 0: if door == 2: time += 1 if door == 3: time += 2 door = random.randint(0,3) totaltime.append(time) print(sum(totaltime)/len(totaltime))