{
"cells": [
{
"cell_type": "raw",
"metadata": {
"collapsed": false
},
"source": [
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"For this problem we need to find the probability for at least three red cards are drew in 5 cards that was drawing from a standard deck. We know that the set of deck cards is a total of 52 cards with two colors, half black and half red. First we need to create a function to draw the cards from the deck in order to see if there is at least 3 red cards. And then we need to randomly shuffle the deck which is a variable that is created to represent both colors, then we will create a if then statement and then calculate the probability."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"import numpy as np\n",
"\n",
"def cards():\n",
" deck=[\"black\" for a in range(26)]+[\"red\" for a in range(26)]\n",
" np.random.shuffle(deck)\n",
" thefirstfivecards=deck[:5]\n",
" number_of_redcards=thefirstfivecards.count(\"red\")\n",
"\n",
" if number_of_redcards>=3:\n",
" return 1\n",
" else:\n",
" return 0 "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"iterations=100000\n",
"result =[cards() for a in range(iterations)]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"probability=(sum(result)/iterations)*100"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"My code does not run to tell me the probalibity for at least 3 red cards,but I believe the probability might be about 49 to 50 percent."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (system-wide)",
"language": "python",
"metadata": {
"cocalc": {
"description": "Python 3 programming language",
"priority": 100,
"url": "https://www.python.org/"
}
},
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}