This project implements a simulation of the famous Monty Hall probability puzzle. The implementation allows users to play the game through a terminal interface and includes an optional Streamlit dashboard for visual analysis.
- The Monty Hall Problem
- Project Structure
- Installation
- Usage
- Implementation Details
- Streamlit Dashboard
- Learning Outcomes
The Monty Hall problem is a famous probability puzzle based on the American television game show "Let's Make a Deal" and named after its original host, Monty Hall.
- A contestant is presented with three doors
- Behind one door is a valuable prize (e.g., a car)
- Behind the other two doors are less desirable prizes (e.g., goats)
- The contestant selects a door
- The host, who knows what's behind each door, opens a different door revealing a goat
- The contestant is then given the option to either:
- Stick with their original choice, or
- Switch to the remaining unopened door
Counterintuitively, the probability of winning increases from 1/3 to 2/3 if the contestant switches doors, demonstrating conditional probability in action.
.
├── images/
│ └── banner.png
│
├── src/
│ ├── monty_hall.py
│ ├── app.py
│
├── requirements.txt
└── README.md
- Clone or download this project
- Ensure you have Python 3.7 or higher installed
- Install the required dependencies:
pip install -r requirements.txtFor the Streamlit dashboard:
pip install streamlitTo play the Monty Hall game in the terminal:
# Add the src directory to Python path and run
python src/monty_hall.pyThe core implementation includes:
- Door randomization: Random assignment of the prize behind doors
- Player selection: Simulating contestant's initial choice
- Host behavior: The host always reveals a goat behind an unselected door
- Decision simulation: Supporting both "stay" and "switch" strategies
- Result tracking: Recording game outcomes for analysis
For a visual exploration of the Monty Hall problem, an interactive Streamlit dashboard is provided:
To run the dashboard:
streamlit run src/app.pyThe dashboard includes:
- Interactive game simulation
- Probability visualization
- Historical results tracking
- Strategy comparison charts
Through this project, you will:
-
Enhance Python programming skills with a focus on:
- Object-oriented design
- Statistical simulation
- Interactive terminal applications
-
Develop a deep understanding of:
- Conditional probability
- The Monty Hall paradox
- Empirical verification of statistical theories
-
Gain experience with:
- Writing comprehensive test suites
- Creating interactive dashboards with Streamlit
- Analyzing and visualizing probability distributions
