Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created March 7, 2024 14:34
Show Gist options
  • Save hvnsweeting/e0f62fda4339e4c913e8d84053da2036 to your computer and use it in GitHub Desktop.
Save hvnsweeting/e0f62fda4339e4c913e8d84053da2036 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "0afbc8fa-99bc-4108-98d3-82dcc055bb40",
"metadata": {},
"source": [
"# Welcome to Python @ Pymi 2403 - https://pymi.vn"
]
},
{
"cell_type": "markdown",
"id": "f782eb2b-4e15-4490-b2d4-857228f7f248",
"metadata": {},
"source": [
"## Chuẩn bị\n",
"- cài python\n",
"- tải tài liệu https://docs.python.org/3/\n",
"- vào slack kênh #prepare https://invite.pymi.vn/"
]
},
{
"cell_type": "markdown",
"id": "837c5698-7b64-4657-8a97-b20a7985d118",
"metadata": {},
"source": [
"https://gitlab.com/pyfml/prepare"
]
},
{
"cell_type": "markdown",
"id": "f11288dd-1b81-4ffe-91ec-b1d9e73f3e18",
"metadata": {},
"source": [
"## chờ tới 7:05 vào lớp"
]
},
{
"cell_type": "markdown",
"id": "45e17a8e-a085-4ce7-bc53-dfdadfbdf3d9",
"metadata": {},
"source": [
"https://projecteuler.net/"
]
},
{
"cell_type": "markdown",
"id": "ddb1e24b-ce60-4476-8525-c4570580009a",
"metadata": {},
"source": [
"https://projecteuler.net/problem=1\n",
"\n",
"Multiples of 3 or 5\n",
"Problem 1\n",
"\n",
"> If we list all the natural numbers below 10\n",
"> that are multiples of 3 or 5 , we get and 3 5 6 9 . The sum of these multiples is 23\n",
"> Find the sum of all the multiples of 3 or 5 below 1000.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d9254cde-7ade-4b97-bb15-4bde4d6e852d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"233168"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(i for i in range(1000) if i % 3 == 0 or i % 5 == 0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "71bf194f-d392-4d34-838b-b5a7eb00eac1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3de6c743-b275-4dba-ae0c-f35d6232433a",
"metadata": {},
"source": [
"### thoi gian, dia diem , hoc phi"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e01f8bcc-07a7-4f37-8c35-22684fb6cc21",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thu Mar 7 07:46:49 PM +07 2024\n"
]
}
],
"source": [
"!date"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "b78b3edd-b32e-4103-87d1-88fd5fe1ea04",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thu Mar 7 08:04:46 PM +07 2024\n"
]
}
],
"source": [
"!date"
]
},
{
"cell_type": "markdown",
"id": "ac465c06-005b-4b9e-87a0-26d9a8dbf354",
"metadata": {},
"source": [
"## doc\n",
"https://docs.python.org/3/tutorial/introduction.html\n"
]
},
{
"cell_type": "markdown",
"id": "d03b5113-99a2-4eb2-a884-e3459c3ff920",
"metadata": {},
"source": [
"## Pymi way"
]
},
{
"cell_type": "markdown",
"id": "0f038e91-0acc-440b-9dab-b45e8293178a",
"metadata": {},
"source": [
"### start python interpreter\n",
"```\n",
"$ python3\n",
"Python 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] on linux\n",
"Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
">>> 1+1\n",
"2\n",
">>> exit()\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "ed46b204-a566-4e4d-886c-391f6edf7fd8",
"metadata": {},
"source": [
"### prompt `>>>`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e053235-23db-4b52-938f-1f432eb795a0",
"metadata": {},
"outputs": [],
"source": [
">>> 1 + 1 + 1\n",
"3\n",
">>> sum(i for i in range(1000) if i % 3 == 0 or i % 5 == 0)\n",
"233168\n"
]
},
{
"cell_type": "markdown",
"id": "c3323f35-b336-4395-ba9b-504196c08288",
"metadata": {},
"source": [
"## numbers"
]
},
{
"cell_type": "markdown",
"id": "adddefad-5250-42e0-a83a-bcf1e4139dce",
"metadata": {},
"source": [
"### interger"
]
},
{
"cell_type": "markdown",
"id": "71b957a8-e0e2-4331-9970-037a37af7fec",
"metadata": {},
"source": [
"### add (+)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "fcfe8f2e-3300-4d09-b4bc-f152d8fab77a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ee8e1037-d850-4a2c-916a-def976e797b5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 + 2"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "43bd4613-825a-49df-858b-c522f3446f90",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7394872318947123987413298749827349812749817239847123984712983749128374987124198192796124020692479505288185528318509184730300225"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"213479812374892317498231789473129847219837498312813 + 7394872318947123987413298749827349812749817239847123984712983749128374987123984712983749128374981273498712398471289347231987412"
]
},
{
"cell_type": "markdown",
"id": "78bd040e-b7d7-46c1-878d-e98ef01d4999",
"metadata": {},
"source": [
"### lớp kết luận\n",
"Cộng thoải mái "
]
},
{
"cell_type": "markdown",
"id": "a5672334-ebe7-46af-a741-f87b38741a48",
"metadata": {},
"source": [
"### substract (-)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e9c99d8e-92f9-4b59-b94f-48e5833b1e8b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-17915631485892116352170"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"12739812839182379812- 17928371298731298731982"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "19cee447-b30c-4d69-85fc-0f1709eeb275",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-1275357567895401822"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"-32141324123-41234123412341234-1234123412341324123-412342"
]
},
{
"cell_type": "markdown",
"id": "2db30879-3fe0-4c56-8b0d-73f32bd27461",
"metadata": {},
"source": [
"### lớp kết luận: trừ thoải mái "
]
},
{
"cell_type": "markdown",
"id": "060e1b0f-8691-4f1d-bc41-25749bd2d1ed",
"metadata": {},
"source": [
"### Multiply (*)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "9fa5b754-09e0-4554-a0e9-f50b99ef7bba",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"16380364570993065538972355953543894002167725161908462328840747751979680169045272411005841"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"127985798317598759817489217498712983712983721 * 127985798317598759817489217498712983712983721"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "5ebac1f1-65f8-4ec0-8598-95e7d376398d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"268316343478644836041527646506412390327100033187393365488252261413249330763375769287312573739985454573897275475318749097420285472732542447874596229804939397919155060820721863532447968074743613461905353610331307166676744647530218155375770872646633450024878837508539391585362949414879510559540331716401304987619696359575647892436958992877084991494677984434586910451513936244020655445601197309432077929174169697420271651915194196697342009808834752579672735337236929357154878852306058142796613847436383616189342404596225447690728378251592902409555351114185077553016926390219648139359531757930296621656572504839219613586681556600080917573298590765835572453297198578683125805891520244313498890990474239623198895805972711377395930860396808956147373304949608848580164654611856607812162559000870502619247963794219456161287348859595565702136379134308659022703940212700806354152132593447732495378678607885056763088040790185146375268839918746321773865475758590300638521765166636872597030941368282347433005918751251040912355435365445895632915348172430183132563393192098095680405346577141272351314296006506180720224715434285735271759387589573598799091347178274653905012794714590703725694045005019523168950772141125142143652934548453662725487624355683510059721236577686839382451299449772391356543899393929315697119932011713374600617769286204810693145260094666415079621488493495510235800773766072099577105185388901219463592950155745207890781544124644363347299824892671069061625535928510421830110506606686929210082074494423088501104873026245758983847648503870357652433341962998478891691593243616637842346474313940980943943048060478844946970480810300246886113246408927394822781204203639835838722036836510768768373658585001000554644765818969172478930731878700007286464759711132932539793305336117281"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"16380364570993065538972355953543894002167725161908462328840747751979680169045272411005841163803645709930655389723559535438940021677251619084623288407477519796801690452724110058411638036457099306553897235595354389400216772516190846232884074775197968016904527241100584116380364570993065538972355953543894002167725161908462328840747751979680169045272411005841163803645709930655389723559535438940021677251619084623288407477519796801690452724110058411638036457099306553897235595354389400216772516190846232884074775197968016904527241100584116380364570993065538972355953543894002167725161908462328840747751979680169045272411005841163803645709930655389723559535438940021677251619084623288407477519796801690452724110058411638036457099306553897235595354389400216772516190846232884074775197968016904527241100584116380364570993065538972355953543894002167725161908462328840747751979680169045272411005841 * 16380364570993065538972355953543894002167725161908462328840747751979680169045272411005841163803645709930655389723559535438940021677251619084623288407477519796801690452724110058411638036457099306553897235595354389400216772516190846232884074775197968016904527241100584116380364570993065538972355953543894002167725161908462328840747751979680169045272411005841163803645709930655389723559535438940021677251619084623288407477519796801690452724110058411638036457099306553897235595354389400216772516190846232884074775197968016904527241100584116380364570993065538972355953543894002167725161908462328840747751979680169045272411005841163803645709930655389723559535438940021677251619084623288407477519796801690452724110058411638036457099306553897235595354389400216772516190846232884074775197968016904527241100584116380364570993065538972355953543894002167725161908462328840747751979680169045272411005841"
]
},
{
"cell_type": "markdown",
"id": "7e105aff-471b-4b9d-b4b8-71bfa317f422",
"metadata": {},
"source": [
"### lớp kết luận: nhân thoải mái "
]
},
{
"cell_type": "markdown",
"id": "cb205d44-b130-4ab6-914a-7ef78624748a",
"metadata": {},
"source": [
"### Power: phép lũy thừa (**)"
]
},
{
"cell_type": "markdown",
"id": "35041023-1f40-4799-9f5f-f4b0522ea6c5",
"metadata": {},
"source": [
"## 2 ^ 64"
]
},
{
"cell_type": "markdown",
"id": "057d81b5-17fa-4990-861c-9db03c57d852",
"metadata": {},
"source": [
"### 2 to the power of 16"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "50d52045-fe8d-471b-b780-60dde5b84559",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"65536"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2**16"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "c2c46688-cf91-424e-80c7-4fddfec6b764",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"18446744073709551616"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2**64"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "ed137d50-3f51-4026-bb96-35900f36ff60",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1000000000"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"10**9"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "d6af6c38-efab-4f59-b2f1-9c19ea6d69f5",
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/.virtualenvs/py3/lib/python3.11/site-packages/IPython/core/formatters.py:708\u001b[0m, in \u001b[0;36mPlainTextFormatter.__call__\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 701\u001b[0m stream \u001b[38;5;241m=\u001b[39m StringIO()\n\u001b[1;32m 702\u001b[0m printer \u001b[38;5;241m=\u001b[39m pretty\u001b[38;5;241m.\u001b[39mRepresentationPrinter(stream, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mverbose,\n\u001b[1;32m 703\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmax_width, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnewline,\n\u001b[1;32m 704\u001b[0m max_seq_length\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmax_seq_length,\n\u001b[1;32m 705\u001b[0m singleton_pprinters\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msingleton_printers,\n\u001b[1;32m 706\u001b[0m type_pprinters\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtype_printers,\n\u001b[1;32m 707\u001b[0m deferred_pprinters\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdeferred_printers)\n\u001b[0;32m--> 708\u001b[0m \u001b[43mprinter\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpretty\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 709\u001b[0m printer\u001b[38;5;241m.\u001b[39mflush()\n\u001b[1;32m 710\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m stream\u001b[38;5;241m.\u001b[39mgetvalue()\n",
"File \u001b[0;32m~/.virtualenvs/py3/lib/python3.11/site-packages/IPython/lib/pretty.py:393\u001b[0m, in \u001b[0;36mRepresentationPrinter.pretty\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 390\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m \u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01min\u001b[39;00m _get_mro(obj_class):\n\u001b[1;32m 391\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mcls\u001b[39m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtype_pprinters:\n\u001b[1;32m 392\u001b[0m \u001b[38;5;66;03m# printer registered in self.type_pprinters\u001b[39;00m\n\u001b[0;32m--> 393\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtype_pprinters\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcycle\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 394\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 395\u001b[0m \u001b[38;5;66;03m# deferred printer\u001b[39;00m\n\u001b[1;32m 396\u001b[0m printer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_in_deferred_types(\u001b[38;5;28mcls\u001b[39m)\n",
"File \u001b[0;32m~/.virtualenvs/py3/lib/python3.11/site-packages/IPython/lib/pretty.py:778\u001b[0m, in \u001b[0;36m_repr_pprint\u001b[0;34m(obj, p, cycle)\u001b[0m\n\u001b[1;32m 776\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"A pprint that just redirects to the normal repr function.\"\"\"\u001b[39;00m\n\u001b[1;32m 777\u001b[0m \u001b[38;5;66;03m# Find newlines and replace them with p.break_()\u001b[39;00m\n\u001b[0;32m--> 778\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mrepr\u001b[39m(obj)\n\u001b[1;32m 779\u001b[0m lines \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39msplitlines()\n\u001b[1;32m 780\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m p\u001b[38;5;241m.\u001b[39mgroup():\n",
"\u001b[0;31mValueError\u001b[0m: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit"
]
}
],
"source": [
"2**99999"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "ad64c5f6-ebc0-4a82-b475-3223fc38eddd",
"metadata": {},
"outputs": [],
"source": [
"x = 2**99999"
]
},
{
"cell_type": "markdown",
"id": "dfb38b2f-bce6-402e-8c60-df42e1f61163",
"metadata": {},
"source": [
"Ctrl C để dừng chương trình "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99389082-33b3-4e4a-957e-f7bef52889bf",
"metadata": {},
"outputs": [],
"source": [
">>> x=2**13723213818927391\n",
"^CTraceback (most recent call last):\n",
" File \"<stdin>\", line 1, in <module>\n",
"KeyboardInterrupt\n"
]
},
{
"cell_type": "markdown",
"id": "a8c3979c-e5f5-4225-b4f3-d519d77f4c10",
"metadata": {},
"source": [
"### Divide (/)\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "f5ad2256-c5ba-4423-b53f-e577fdefd017",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4/2"
]
},
{
"cell_type": "markdown",
"id": "9af94901-2023-4eec-9cf1-0224d0a70964",
"metadata": {},
"source": [
"## / - đọc là??? - slash /slæʃ/\n",
"- xoẹt\n",
"- gạch chéo\n",
"- gạch huyền\n",
"- xuyệt trái \n",
"- ...\n",
"## \\ - backslash"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c59e68fc-940f-4ee5-a6d5-9679d4323140",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 29,
"id": "70dcfa90-0b0f-4f2e-928b-931c49addbb2",
"metadata": {},
"outputs": [],
"source": [
"x = 4/2"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "d1ae1320-7ff7-4e62-b838-12cfb5fc2f47",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(x)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "a1ca9d17-6793-4477-9bb4-1e232d0f9037",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(4)"
]
},
{
"cell_type": "markdown",
"id": "34bf6678-2a20-478a-a769-52631e84dc5b",
"metadata": {},
"source": [
"### integer"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "875ecb0c-4112-4d9b-8000-98ead9f94f68",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(4.0)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "fbe35af1-5a2e-4dcd-9eb7-b0a30cf59086",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.1"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4.1"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "1111637a-f50a-43c3-83e9-008ca7eeba9c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.14"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3.14"
]
},
{
"cell_type": "markdown",
"id": "5e3e01a4-135d-4897-90a7-efa80b4a687b",
"metadata": {},
"source": [
"số thực == số hữu tỷ + số vô tỷ "
]
},
{
"cell_type": "markdown",
"id": "ae4debb6-5e52-4465-9724-44699fb58cf0",
"metadata": {},
"source": [
"- hữu tỷ: có tỉ lệ / tỷ số : viết thành phân số được\n",
"- vô tỷ: không có tỷ lệ/ : không viết thành phân số được"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "5f8356f8-7616-4eb9-9294-79312c778628",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.5"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1/2"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "b11632ed-7bb8-415e-b578-bb9cf8f961fe",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3333333333333333"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1/3"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "86941f39-8c12-4d41-8c37-e345f1c9ed81",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.4142135623730951"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2**(1/2)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "8940ee26-f899-42e3-b236-f6659d983e56",
"metadata": {},
"outputs": [],
"source": [
"y = 1/3"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "e0d08d48-1eec-4b9c-bdea-4ec9c138ea7a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3333333333333333"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "344a38ad-638d-493b-b0ca-18be8b5b93f2",
"metadata": {},
"outputs": [],
"source": [
"z = 2.0"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "4a379fcd-8647-4b4d-8e5c-d318155f4223",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(z)"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "d18e120c-0a5e-4204-9874-42d4c29a5288",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 == 0.2"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "4d1c495d-fe47-4103-9548-aa6ffb6a9cd9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 + 0.1 == 0.3"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "725c5f0d-fddd-4060-93d4-2bc8e60f4a3a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.30000000000000004"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 + 0.1"
]
},
{
"cell_type": "markdown",
"id": "797c5803-12fb-42de-b348-c15f93b308db",
"metadata": {},
"source": [
"https://pymi.vn/blog/why-not-float/"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "86bac000-7b40-48cd-ae9d-a61fc4e15935",
"metadata": {},
"outputs": [],
"source": [
"x = 0.1"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "d27858b1-0524-4bd0-b60e-8f38a764ef35",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3602879701896397, 36028797018963968)"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.as_integer_ratio()"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "fc100fe6-9ecf-45cc-908a-dc0174e64cc7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-2"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"36028797018963968-3602879701896397*10"
]
},
{
"cell_type": "markdown",
"id": "39c830e8-bb9e-4952-a71a-22c6594160b9",
"metadata": {},
"source": [
"IEEE754 https://en.wikipedia.org/wiki/IEEE_floating_point"
]
},
{
"cell_type": "markdown",
"id": "e435866b-60f4-4643-b747-c83fd053c09f",
"metadata": {},
"source": [
"http://docs.python.org/tutorial/floatingpoint.html"
]
},
{
"cell_type": "markdown",
"id": "7b039a46-083f-4521-ad74-b5e26d530298",
"metadata": {},
"source": [
"https://docs.python.org/3/library/decimal.html"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "9a821693-548e-4ceb-8fa8-d13ea94c136b",
"metadata": {},
"outputs": [],
"source": [
"f = 4/2"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "67494bcf-d768-47db-88bb-718dc047b030",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.0"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 + 2.0"
]
},
{
"cell_type": "markdown",
"id": "d13b4b1d-b6ae-41a7-974a-980f968751cd",
"metadata": {},
"source": [
"### ket luan: float là kiểu GẦN ĐÚNG, không so sánh =="
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "06f402a5-9adf-48e9-b415-afd3c15ddbbd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5d066251-4b93-45d4-a932-9016e3b7a5d6",
"metadata": {},
"source": [
"## float uk /fləʊt/ usmm /floʊt/"
]
},
{
"cell_type": "markdown",
"id": "9541948d-06fa-48ae-8e2e-ec666344e5d3",
"metadata": {},
"source": [
"### cache /kæʃ/ cash"
]
},
{
"cell_type": "markdown",
"id": "6e94f099-ce86-492f-82e4-5a0b1b67041b",
"metadata": {},
"source": [
"## suit /suːt/\n",
"## test suite /swiːt/ sweet"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "b2663a3e-1ff2-4d93-8133-a6280eb64e48",
"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)",
"Cell \u001b[0;32mIn[61], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"1/0"
]
},
{
"cell_type": "markdown",
"id": "13375acd-f8d6-4ef2-a38d-ea38f61dc013",
"metadata": {},
"source": [
"Khi 1 chia 0, XẢY RA EXCEPTION ZeroDivisionError"
]
},
{
"cell_type": "markdown",
"id": "162d1e84-52f0-406f-a4ad-ade1a04d8327",
"metadata": {},
"source": [
"### exception"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "135bf1dd-f82c-4692-905f-69e910f0e43f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"50 - 5*6"
]
},
{
"cell_type": "markdown",
"id": "735c5317-0102-4d54-9cb3-065456b892b8",
"metadata": {},
"source": [
"### () parenthesis"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "d33618e2-74e1-487b-9594-b448611c4341",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"270"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(50 - 5) * 6"
]
},
{
"cell_type": "markdown",
"id": "26d971f0-6955-4211-b066-36d70ba46a8a",
"metadata": {},
"source": [
"## floor divsion "
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "77093f2f-411f-49b7-8744-38386425bcf8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5/2"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "dd030d73-590a-47a6-adeb-1b3468a7cb0c",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 // 2"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "b6c3756f-a799-40f0-8224-3242e0cc028e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"_"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "207c0255-229f-487b-8c90-fff2fd8bf270",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 68,
"id": "075fc2f1-8824-454a-b057-630f05f540e3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thu Mar 7 09:19:36 PM +07 2024\n"
]
}
],
"source": [
"!date"
]
},
{
"cell_type": "markdown",
"id": "0428e2c9-7f28-4a09-a02b-12dd0e9edc8f",
"metadata": {},
"source": [
"## Complex number"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "46e185c1-eca2-42e4-b8a5-57f8ec53fd08",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"complex"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(3 + 2j)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "6e60494c-d330-44d5-9d3b-14c998155eec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(4+6j)"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = (3 + 2j)\n",
"y = 1 + 4j\n",
"z = x + y\n",
"z"
]
},
{
"cell_type": "markdown",
"id": "42346dd9-cc4a-4dda-9565-072e5819d23e",
"metadata": {},
"source": [
"## modulo (%) / remainder"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "983a73a9-e816-4e01-abaa-fcaf860c09ce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"10 // 3"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "4162e3f0-672b-4e4d-878a-9d7be44d39e2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"10 % 3 "
]
},
{
"cell_type": "markdown",
"id": "121b24ba-a6ef-454e-ae09-19a7343e4eae",
"metadata": {},
"source": [
"700000000000"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "6bc8a026-0262-4303-8329-c86d0c45a4ec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"700000000000 % 7"
]
},
{
"cell_type": "markdown",
"id": "08aca993-52f8-4c67-bbf0-cec7adf4e65c",
"metadata": {},
"source": [
"giảm kích thước bài toán có tính chu kỳ "
]
},
{
"cell_type": "markdown",
"id": "ac268f34-2371-41f5-a46c-4c8e6273d16d",
"metadata": {},
"source": [
"## 2024 - giáp thìn"
]
},
{
"cell_type": "markdown",
"id": "ca5c936d-811a-4415-891e-e2627ea80aea",
"metadata": {},
"source": [
"2036 - ??? thìn"
]
},
{
"cell_type": "markdown",
"id": "a157950e-4c95-40c8-b016-d8ea7ce5429c",
"metadata": {},
"source": [
"- giáp: thiên can - 10 thiên can - \n",
"0: canh\n",
"tân\n",
"nhâm \n",
"quý\n",
"giáp \n",
"ất \n",
"bính\n",
"đinh\n",
"mậu \n",
"kỷ\n",
"- thìn: địa chi - 12 địa chi - 12 con giáp "
]
},
{
"cell_type": "markdown",
"id": "80f18f78-1135-4405-9cc3-0fb6379827d5",
"metadata": {},
"source": [
"### 1269 năm gì? "
]
},
{
"cell_type": "markdown",
"id": "80b35d36-ba98-40d5-a2d6-756ce8c60dba",
"metadata": {},
"source": [
"https://canchi.pymi.vn"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cf06c3b-4f6f-4358-b9d7-30f7bb17594a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment