{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Coin Flip Probability Calculator\n", "*by Techman*\n", "
\n", "\n", "## Problem Statement\n", "*Is the probability of coin flip landing on heads actually 50%?*\n", "\n", "## Solution 1\n", "Below is a simple python script that randomly flips a coin (0 = heads, 1 = tails) for the number of times the user specifies. Go ahead, try it yourself. Are they really 50/50? " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Solution 1: \n", "\n", "How many times do you want to flip the coin? 50\n", "\n", "38.0% (19) were Heads \n", "62.0% (31) were Tails\n" ] } ], "source": [ "#Heads Tails Prob Calculator by Techman\n", "import random\n", "total = int(input(\"Solution 1: \\n\\nHow many times do you want to flip the coin? \"))\n", "heads, tails = 0, 0\n", "for i in range(total):\n", "\tif random.randint(0,1) == 0:\n", "\t\theads += 1\n", "\telse:\n", "\t\ttails += 1\n", "print(\"\\n{headsp}% ({heads}) were Heads \\n{tailsp}% ({tails}) were Tails\".format(heads=heads, tails=tails, headsp=round(heads*100/total, 2), tailsp=round(tails*100/total, 2)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "