Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Added some pretty print functions and percentage for easier comprehension #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
63 changes: 40 additions & 23 deletions monty-hall.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@
" # you stick with your original choice:\n",
" if doors_d[my_choice] == 'car':\n",
" return True # you win!\n",
" return False # you lose :("
" return False # you lose :(\n",
"\n",
"print(never_switch())\n",
"print(never_switch())\n",
"print(never_switch())\n",
"print(never_switch())"
]
},
{
Expand All @@ -209,13 +214,15 @@
"outputs": [],
"source": [
"# ok, let's try this out!\n",
"print(always_switch())\n",
"print(always_switch())\n",
"print(always_switch())\n",
"print(\"\\nAlways Switching results in winning?\")\n",
"print(\" -\", always_switch())\n",
"print(\" -\", always_switch())\n",
"print(\" -\", always_switch())\n",
"\n",
"print(never_switch())\n",
"print(never_switch())\n",
"print(never_switch())\n"
"print(\"\\nNever Switching results in winning?\")\n",
"print(\" -\", never_switch())\n",
"print(\" -\", never_switch())\n",
"print(\" -\", never_switch())\n"
]
},
{
Expand Down Expand Up @@ -256,8 +263,10 @@
"for i in range(N):\n",
" if always_switch():\n",
" won_count += 1\n",
" \n",
"print('With always_switch(), I won', won_count, 'of', N, 'tries')"
"\n",
"percentage = (won_count/N)*100\n",
"\n",
"print('With always_switch(), I won', won_count, 'of', N, 'tries', f\"({percentage}%)\")"
]
},
{
Expand All @@ -279,12 +288,14 @@
"outputs": [],
"source": [
"won_count = 0\n",
"N = 1000\n",
"N = 10000\n",
"for i in range(N):\n",
" if never_switch():\n",
" won_count += 1\n",
" \n",
"print('With never_switch(), I won', won_count, 'of', N, 'tries')"
"\n",
"percentage = (won_count/N)*100\n",
"\n",
"print('With never_switch(), I won', won_count, 'of', N, 'tries', f\"({percentage}%)\")"
]
},
{
Expand Down Expand Up @@ -418,13 +429,15 @@
},
"outputs": [],
"source": [
"print(always_switch2(100))\n",
"print(always_switch2(100))\n",
"print(always_switch2(100))\n",
"print(\"\\nAlways Switching results in winning when there are 100 doors?\")\n",
"print(\" -\", always_switch2(100))\n",
"print(\" -\", always_switch2(100))\n",
"print(\" -\", always_switch2(100))\n",
"\n",
"print(never_switch2(100))\n",
"print(never_switch2(100))\n",
"print(never_switch2(100))\n"
"print(\"\\nNever Switching results in winning when there are 100 doors?\")\n",
"print(\" -\", never_switch2(100))\n",
"print(\" -\", never_switch2(100))\n",
"print(\" -\", never_switch2(100))\n"
]
},
{
Expand Down Expand Up @@ -452,16 +465,20 @@
"for i in range(N):\n",
" if always_switch2(M):\n",
" won_count += 1\n",
" \n",
"print('With always_switch2() and', M, 'doors, I won', won_count, 'of', N, 'tries')\n",
"\n",
"percentage = (won_count/N)*100\n",
"\n",
"print('With always_switch2() and', M, 'doors, I won', won_count, 'of', N, 'tries', f\"({percentage}%)\")\n",
"\n",
"won_count = 0\n",
"\n",
"for i in range(N):\n",
" if never_switch2(M):\n",
" won_count += 1\n",
" \n",
"print('With never_switch2() and', M, 'doors, I won', won_count, 'of', N, 'tries')"
"\n",
"percentage = (won_count/N)*100\n",
"\n",
"print('With never_switch2() and', M, 'doors, I won', won_count, 'of', N, 'tries', f\"({percentage}%)\")"
]
},
{
Expand Down Expand Up @@ -684,7 +701,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down