Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created October 10, 2019 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvnsweeting/77085beba5e88527beb2534e5df30eac to your computer and use it in GitHub Desktop.
Save hvnsweeting/77085beba5e88527beb2534e5df30eac to your computer and use it in GitHub Desktop.
01. Intro, integer, float, exception - học python tại https://pymi.vn lớp Hà Nội 2019/10
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Welcome to Pymi.vn\n",
"## Không cung cấp wifi\n",
"\n",
"## Prepare \n",
"### Cài Python\n",
"### Tải tài liệu \n",
"### Vào Slack \n",
"\n",
"https://gitlab.com/pyfml/prepare"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Vao channel #pymiprepare trong invite.pymi.vn"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Học lập trình Python chất lượng số 1 Việt Nam - đào tạo học viên từ không biết gì thành lập trình viên chuyên nghiệp. Đã đào tạo hơn 200 lập trình viên sau 15 ...\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0, 5, 10, 15, 0, 3, 6, 9, 12, 15, 18]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(range(20))[::5] + list(range(20))[::3]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"233168"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(i for i in range(1000) if i % 3 == 0 or i % 5 == 0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://www.projecteuler.net/problem=1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
">>> 1 + 1\n",
"2\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `>>>` - Prompt"
]
},
{
"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": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Theo kiểu Anh Mỹ: /ˈpaɪ.θɑːn/ (đọc là pai-thon)\n",
"Theo kiểu Anh Anh: /ˈpaɪ.θən/ (đọc là pai-thơn)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Number"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add (+)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1214"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1213"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"39464563721344125310456256225110723"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"39425798437598437985798432759284375 + 38765283745687324657823465826348"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"734348276578437986"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1111+734348276578436875"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## cộng thoải mái "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Subtract (-)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-855634922984360"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2843274- 855634925827634"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-3295781"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"11 + -3295792"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## trừ thoải mái "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"45504000"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"1920 * 23700"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## nhân - multiply (`*`)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 * 4"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12101400791840152565552402246"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"283174928374 * 42734718293483129"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1192879127419874981274891272987811928791274198749812748912729878119287912741987498127489127298781192879127419874981274891272987811928791274198749812748912729878119287912741987498127489127298781192879127419874981274891272987811928791274198749812748912729878119287912741987498127489127298781192879127419874981274891272987811928791274198749812748912729878 * 1192879127419874981274891272987811928791274198749812748912729878119287912741987498127489127298781192879127419874981274891272987811928791274198749812748912729878119287912741987498127489127298781192879127419874981274891272987811928791274198749812748912729878 "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884 * 1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n",
"1422960612634002331400962297383829847634654568475081201184896516454656631827969268483927468191946108369171102537861558430874187276701720239253830382775870664550923197487674822821499674325872290793777729571073391715899450990723555805823939185684350556432585249442282258276141375324953814252494422822582761413753249538142524944228225827614137532495381425107146220994875908235228724075869509659357125913905633131048490879478565043030687289139748562230638605365148022355219481866395524824250798657378375475662471687432624479458345331987565062794196170064509301168802203735008715180138842240188842845318193894884\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## nhân thoải mái "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `/` - chia - divide"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `/` - slash\n",
"- xoạc\n",
"- xổ phải\n",
"- xoạc trước\n",
"- sượt\n",
"- sược\n",
"- gạch chéo "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `\\` - backslash\n",
"- xoạc sau\n",
"- gạch chéo\n",
"- xổ trái\n",
"- "
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 / 2"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"ename": "ZeroDivisionError",
"evalue": "division by zero",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-24-1335e5924dd4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m11111\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"11111 / 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# xảy ra exception ZeroDivisionError"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 /2"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(1234132)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Integer integer/ˈɪntɪdʒə/ "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## cache cache/kaʃ/ \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## RESORT resort/rɪˈzɔːt/ "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## suite suite/swiːt/ "
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(5/2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## float float/fləʊt/ "
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Float"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gồm\n",
"### Số hữu tỷ - có tỷ lệ - biểu diễn được ở dạng phân số\n",
"### Số vô tỷ - không tỷ lệ \n",
"- căn 2 của 2\n",
"- pi "
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.141592653589793"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.pi"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.14"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3.14"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## power - mũ - `**`"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"18446744073709551616"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 ** 64"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 ** 1000"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.4142135623730951"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 ** (1/2)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.4142135623730951"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.sqrt(2) # square root"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1 == 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## HAI DAU ="
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 > 4"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 < 5"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 <=5"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 <= 4"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 != 5"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 2 == 3"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + .1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
".1 + .1 + .1 == .3 "
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 + 0.1 == 0.3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://en.wikipedia.org/wiki/IEEE_754"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.30000000000000004"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
".1 + .1 + .1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://pymi.vn/blog/why-not-float/"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"x = 0.1"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3602879701896397, 36028797018963968)"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.as_integer_ratio()"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
"y = 0.3"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(5404319552844595, 18014398509481984)"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y.as_integer_ratio()"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"import decimal"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Decimal('0.3')"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"decimal.Decimal('0.1') +decimal.Decimal('0.1') + decimal.Decimal('0.1') "
]
},
{
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment