A Python simulation of the Monty Hall problem to empirically prove the winning probability with and without switching doors.
In the Monty Hall problem, a contestant picks one of three doors. Behind one door is a car; behind the others are goats. The host opens a different door revealing a goat, then asks if the contestant wants to switch.
Math result: switching raises your win probability from
pip install streamlit
python main.py Winning percentage without switching doors: 33.20%
Winning percentage with switching doors: 66.50%
streamlit run app.py
Then open http://localhost:8501 in your browser.
montyhaal(switch)— simulates a single game. Ifswitch=True, the player switches doors.counter(num)— runsnumgames and returns the win count for each strategy.
- Python 3.x — no external libraries needed.
- streamlit