Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This implementation solves the famous Monty Hall problem, presenting an interact
├─ monty_hall.py
└─ app.py
```

- `README.md`: This descriptive file
- `requirements.txt`: Contains all the required modules and libraries needed to run the project
- `src/monty_hall.py`: Contains the Python program to simulate the Monty Hall game
Expand All @@ -23,6 +24,7 @@ This implementation solves the famous Monty Hall problem, presenting an interact

- Python 3.7 or higher
- Streamlit
- pandas

To install necessary packages, run `pip install -r requirements.txt`.

Expand All @@ -32,7 +34,7 @@ You can play the Monty Hall game simulation by adding the `src` directory to the

`python3 src/monty_hall.py`

To start the Streamlit dashboard, run:
To start the Streamlit dashboard, run:

`streamlit run src/app.py`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import streamlit as st
import pandas as pd
import time

from monty_hall import simulate_games
Expand All @@ -14,11 +15,13 @@

col1, col2 = st.columns(2)
col1.subheader("Win Percentage Without Switching")
chart1 = col1.line_chart(x=None, y=None, width=0, height=400)
chart1.add_rows([1.0]) # Add a row to ensure the chart y-axis starts at 1
chart1 = col1.empty()
no_switch_history = []

col2.subheader("Win Percentage With Switching")
chart2 = col2.line_chart(x=None, y=None, width=0, height=400)
chart2.add_rows([1.0]) # Add a row to ensure the chart y-axis starts at 1
chart2 = col2.empty()
switch_history = []


for i in range(num_games):
# Simulate one game at a time
Expand All @@ -28,9 +31,23 @@
wins_no_switch += num_wins_without_switching
wins_switch += num_wins_with_switching

# # Display the current percentages after each game
chart1.add_rows([wins_no_switch / (i + 1)])
chart2.add_rows([wins_switch / (i + 1)])
no_switch_history.append(wins_no_switch / (i+1))
switch_history.append(wins_switch / (i+1))

data1 = pd.DataFrame({
"Trial": range(1, len(no_switch_history) + 1),
"Switch": no_switch_history
})

data2 = pd.DataFrame({
"Trial": range(1, len(switch_history) + 1),
"Switch": switch_history
})

data1 = data1.set_index("Trial")
chart1.line_chart(data1)
data2 = data2.set_index("Trial")
chart2.line_chart(data2)

# Add a delay to create a slow loop effect
time.sleep(0.01)