From 907c980babd406b1dece8c5a5e42b93526ca272d Mon Sep 17 00:00:00 2001 From: Ulrich <ulrich.kerzel@rwth-aachen.de> Date: Thu, 20 Mar 2025 14:41:37 +0100 Subject: [PATCH] update Monty Hall --- .../solutions/Solution_MontyHall.ipynb | 72 ++++++++++--------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/datascienceintro/solutions/Solution_MontyHall.ipynb b/datascienceintro/solutions/Solution_MontyHall.ipynb index 17ff77f..a297fb9 100644 --- a/datascienceintro/solutions/Solution_MontyHall.ipynb +++ b/datascienceintro/solutions/Solution_MontyHall.ipynb @@ -1,21 +1,10 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { "cell_type": "markdown", + "metadata": { + "id": "aQVYzt-A7so-" + }, "source": [ "# Monty Hall\n", "\n", @@ -25,21 +14,18 @@ "The host of the show lets the contestant make an initial choice, then opens one of the doors (not the one the contestant has chosen) and then offers the contestant the choice to switch doors.\n", "\n", "Is it beneficial to switch the doors?" - ], - "metadata": { - "id": "aQVYzt-A7so-" - } + ] }, { "cell_type": "code", - "source": [ - "import random" - ], + "execution_count": 1, "metadata": { "id": "KuoDvxxe8F3M" }, - "execution_count": 1, - "outputs": [] + "outputs": [], + "source": [ + "import random" + ] }, { "cell_type": "code", @@ -90,14 +76,7 @@ }, { "cell_type": "code", - "source": [ - "num_trials = 5000\n", - "stay_win_rate, switch_win_rate = monty_hall_simulation(num_trials=num_trials)\n", - "\n", - "print(f\"After {num_trials} trials:\")\n", - "print(f\"Winning by staying with the initial choice: \\t {stay_win_rate*100:.2f}%\")\n", - "print(f\"Winning by switching to the other door: \\t {switch_win_rate*100:.2f}%\")" - ], + "execution_count": 12, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -105,18 +84,41 @@ "id": "YOPqK0rd8Q5r", "outputId": "cb585501-1540-46d3-a6e1-e504021f2015" }, - "execution_count": 12, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "After 5000 trials:\n", "Winning by staying with the initial choice: \t 32.60%\n", "Winning by switching to the other door: \t 67.40%\n" ] } + ], + "source": [ + "num_trials = 5000\n", + "stay_win_rate, switch_win_rate = monty_hall_simulation(num_trials=num_trials)\n", + "\n", + "print(f\"After {num_trials} trials:\")\n", + "print(f\"Winning by staying with the initial choice: \\t {stay_win_rate*100:.2f}%\")\n", + "print(f\"Winning by switching to the other door: \\t {switch_win_rate*100:.2f}%\")" ] } - ] -} \ No newline at end of file + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "datascienceintro-eVBNPtpL-py3.11", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.11.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} -- GitLab