Skip to content
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
106 changes: 106 additions & 0 deletions 1103HW_1_Kao.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"輸入一個數字10000\n",
"前三胎生有生女的機率為 0.8714\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"n=int(input(\"輸入一個數字\"))\n",
"g=0\n",
"for i in range(1,n+1):\n",
" #print(\"第\",i,\"次\")\n",
" k = np.random.randint(1,100)\n",
" a=0\n",
" \n",
" while a<3:\n",
" if k>49:\n",
" a+=1\n",
" #print(\"男\") \n",
" k = np.random.randint(1,100)\n",
" if k>49:\n",
" a+=1\n",
" #print(\"男\")\n",
" k = np.random.randint(1,100)\n",
" if k>49:\n",
" a+=1\n",
" #print(\"男\")\n",
" \n",
" else: \n",
" a+=1\n",
" #print(\"女\")\n",
" g+=1\n",
" break\n",
" \n",
" else:\n",
" a+=1\n",
" #print(\"女\")\n",
" g+=1\n",
" break\n",
" \n",
" else:\n",
" a+=1\n",
" #print(\"女\")\n",
" g+=1\n",
" break\n",
" \n",
"print(\"前三胎生有生女的機率為\",g/n)\n",
"#p=g/n\n",
"#print(\"前三胎有女的機率為\",p)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}