Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Homework
Here is the homework for Tibame
影像班 王嘉誠 作業
121 changes: 121 additions & 0 deletions hw_1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"HW_1 count girl birth"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(78) boy (2) girl \n",
"(40) girl \n",
"(3) girl \n",
"(30) girl \n",
"(49) boy (74) boy (9) girl \n",
"(97) boy (92) boy (4) girl \n",
"(58) boy (93) boy (8) girl \n",
"(38) girl \n",
"(56) boy (41) girl \n",
"(19) girl \n",
"1.0\n"
]
}
],
"source": [
"import random as rand\n",
"\n",
"def count_girl_birth(n):\n",
" \n",
" birth_list = []\n",
" girl_count = 0\n",
" \n",
" for i in range(0, n):\n",
" \n",
" child_count = 1\n",
" str_boy = \"({}) boy \"\n",
" str_girl = \"({}) girl \"\n",
" str_result = \"\"\n",
" \n",
" while child_count < 4:\n",
" \n",
" rand_birth = rand.randint(0,99)\n",
" is_girl = True if rand_birth < 49 else False\n",
" child_count += 1\n",
" \n",
" if(is_girl): \n",
" girl_count += 1\n",
" str_result += str_girl.format(rand_birth)\n",
" break\n",
" \n",
" else:\n",
" str_result += str_boy.format(rand_birth)\n",
" \n",
" birth_list.append(str_result)\n",
" \n",
" result_prob = girl_count / n\n",
" \n",
" return birth_list, result_prob\n",
"\n",
"def birth_result(n, show = False):\n",
" \n",
" birth_list, result_prob = count_girl_birth(n)\n",
" \n",
" if(show):\n",
" \n",
" for i in birth_list:\n",
" print(i)\n",
" \n",
" print(result_prob)\n",
" \n",
"\n",
" \n",
"\n",
"birth_result(n = 10, show = True) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.6",
"language": "python",
"name": "python36"
},
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
125 changes: 125 additions & 0 deletions hw_2.ipynb

Large diffs are not rendered by default.