Skip to content

IVDOT80/Monty-Hall-Problem-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Monty Hall Simulation Project

Monty Hall Simulation Banner

Overview

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.

Table of Contents

  1. The Monty Hall Problem
  2. Project Structure
  3. Installation
  4. Usage
  5. Implementation Details
  6. Streamlit Dashboard
  7. Learning Outcomes

The Monty Hall Problem

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.

Problem Statement

  • 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

The Paradox

Counterintuitively, the probability of winning increases from 1/3 to 2/3 if the contestant switches doors, demonstrating conditional probability in action.

Project Structure

.
├── images/
│   └── banner.png
│
├── src/
│   ├── monty_hall.py
│   ├── app.py
│
├── requirements.txt
└── README.md

Installation

  1. Clone or download this project
  2. Ensure you have Python 3.7 or higher installed
  3. Install the required dependencies:
pip install -r requirements.txt

For the Streamlit dashboard:

pip install streamlit

Usage

Terminal Game

To play the Monty Hall game in the terminal:

# Add the src directory to Python path and run
python src/monty_hall.py

Implementation Details

The core implementation includes:

  1. Door randomization: Random assignment of the prize behind doors
  2. Player selection: Simulating contestant's initial choice
  3. Host behavior: The host always reveals a goat behind an unselected door
  4. Decision simulation: Supporting both "stay" and "switch" strategies
  5. Result tracking: Recording game outcomes for analysis

Streamlit Dashboard

For a visual exploration of the Monty Hall problem, an interactive Streamlit dashboard is provided:

To run the dashboard:

streamlit run src/app.py

The dashboard includes:

  • Interactive game simulation
  • Probability visualization
  • Historical results tracking
  • Strategy comparison charts

Learning Outcomes

Through this project, you will:

  1. Enhance Python programming skills with a focus on:

    • Object-oriented design
    • Statistical simulation
    • Interactive terminal applications
  2. Develop a deep understanding of:

    • Conditional probability
    • The Monty Hall paradox
    • Empirical verification of statistical theories
  3. Gain experience with:

    • Writing comprehensive test suites
    • Creating interactive dashboards with Streamlit
    • Analyzing and visualizing probability distributions

About

Project Based Python

Topics

Resources

Stars

Watchers

Forks

Languages