Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created July 29, 2022 02:50
Show Gist options
  • Save hvnsweeting/1d11b521da99b6e4baa78ee6c3033793 to your computer and use it in GitHub Desktop.
Save hvnsweeting/1d11b521da99b6e4baa78ee6c3033793 to your computer and use it in GitHub Desktop.
Học lập trình Python 2022 tại PyMi.vn lớp học lập trình Python tại Hà Nội, TP Hồ Chí Minh, Sài Gòn
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "631f1f47",
"metadata": {},
"source": [
"# Welcome to Pymi.vn"
]
},
{
"cell_type": "markdown",
"id": "610872ec",
"metadata": {},
"source": [
"https://projecteuler.net/"
]
},
{
"cell_type": "markdown",
"id": "8da27eb3",
"metadata": {},
"source": [
"Multiples of 3 or 5\n",
"[Show HTML problem content] \n",
"Problem 1\n",
"\n",
"If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\n",
"\n",
"Find the sum of all the multiples of 3 or 5 below 1000.\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9da18605",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"233168"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(i for i in range(1000) \n",
" if i % 3 == 0 or i % 5 == 0)"
]
},
{
"cell_type": "markdown",
"id": "0655c70c",
"metadata": {},
"source": [
"https://www.familug.org/"
]
},
{
"cell_type": "markdown",
"id": "2757a114",
"metadata": {},
"source": [
"## cách học ở PYMI"
]
},
{
"cell_type": "markdown",
"id": "81fdde90",
"metadata": {},
"source": [
"gõ nhưu trên bảng, không cần ghi chép"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d5ab47d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e8bf7f4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d17cdbd7",
"metadata": {},
"source": [
"## bật Python"
]
},
{
"cell_type": "markdown",
"id": "fd3ba4d5",
"metadata": {},
"source": [
"Gõ python3 \n",
"```py\n",
"Python 3.8.10 (default, Jun 22 2022, 20:18:18) \n",
"[GCC 9.4.0] on linux\n",
"Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n",
">>> 1+1\n",
"2\n",
">>> exit()\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "a7849691",
"metadata": {},
"source": [
"\n",
"## tắt python"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33d703e0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c1fa3e6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "68be6e19",
"metadata": {},
"source": [
"## prompt `>>>`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cbb84776",
"metadata": {},
"outputs": [],
"source": [
">>> 1+1\n",
"2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7bbe178d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6689e29c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "dca945fd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d1b6d822",
"metadata": {},
"source": [
"## phép cộng: + add"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2d4d458c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12525"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"213 + 12312"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "28684c55",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "96b90b04",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 + 2"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4864cf9b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999+111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "caaadf60",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222422222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222220"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110 + 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
]
},
{
"cell_type": "markdown",
"id": "ec013ab9",
"metadata": {},
"source": [
"### kết luận: tính thoải mái "
]
},
{
"cell_type": "markdown",
"id": "11419ff7",
"metadata": {},
"source": [
"## phép trừ (subtract) - "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8bd79e58",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-3"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 - 5"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "5c3804f7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-17236598271487594908827965"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3248921347132984891273 - 17239847192834727893719238"
]
},
{
"cell_type": "markdown",
"id": "290786b3",
"metadata": {},
"source": [
"### trừ thoải mái"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "29c7f20d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"--1"
]
},
{
"cell_type": "markdown",
"id": "7ea07b69",
"metadata": {},
"source": [
"## phép nhân (multiply) *"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "d0abe6d5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 * 5"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "affbe2f0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"22369529189805693900270936790708454867929083500651552938855527347993980438009138680631890738"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"17349127349871329847129847231984712983748921373719874 * 1289374891237489127349877981928734982137"
]
},
{
"cell_type": "markdown",
"id": "db8bb927",
"metadata": {},
"source": [
"https://docs.python.org/3/tutorial/introduction.html#using-python-as-a-calculator"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "8699163b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 2 * 2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "1667f8cd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 * (2+1)"
]
},
{
"cell_type": "markdown",
"id": "4d0cb534",
"metadata": {},
"source": [
"## phép chia - divide / "
]
},
{
"cell_type": "markdown",
"id": "9e45d326",
"metadata": {},
"source": [
"## đây / là dấu gì ? - slash\n",
"- Chung: xược\n",
"- Hoàng: xổ chéo \n",
"- Minh: xục\n"
]
},
{
"cell_type": "markdown",
"id": "7850b4ae",
"metadata": {},
"source": [
"## đây \\ là dấu gì - backslash\n",
"- Chung: ???\n",
"- Hoàng: xổ ???\n",
"- Minh: ???"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "183dbcc0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 / 2"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "9fc20dd0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1+1"
]
},
{
"cell_type": "markdown",
"id": "9bc71fb7",
"metadata": {},
"source": [
"## kiểu dữ liệu : data type "
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "38be4230",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2)"
]
},
{
"cell_type": "markdown",
"id": "0e71aa0b",
"metadata": {},
"source": [
"## int - integer - số nguyên"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "99f13d62",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(-1)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "b70c6673",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2.0)"
]
},
{
"cell_type": "markdown",
"id": "0daef2cd",
"metadata": {},
"source": [
"/fləʊt/ https://www.lexico.com/definition/float"
]
},
{
"cell_type": "markdown",
"id": "cdaf8e28",
"metadata": {},
"source": [
"# float ? số thực\n",
"## số thực ? \n",
"Tập số tạo bởi 2 tập: số hữu tỷ + số vô tỷ"
]
},
{
"cell_type": "markdown",
"id": "cc6f2c2d",
"metadata": {},
"source": [
"### số hữu tỷ \n",
"- hữu: có \n",
"- tỷ: tỷ lệ/ tỷ số\n",
"- số có dạng tỷ số/ tỷ lệ: phân số"
]
},
{
"cell_type": "markdown",
"id": "8190ec11",
"metadata": {},
"source": [
"### số vô tỷ: không thể viết ở dạng phân số"
]
},
{
"cell_type": "markdown",
"id": "a077a347",
"metadata": {},
"source": [
"- căn 2\n",
"- pi"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "8f5f73cd",
"metadata": {},
"outputs": [],
"source": [
"pi = 3.14"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "9cd1051b",
"metadata": {},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "35833987",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.141592653589793"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.pi"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "5c66347c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.4142135623730951"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.sqrt(2)"
]
},
{
"cell_type": "markdown",
"id": "c923340a",
"metadata": {},
"source": [
"## float - biểu diễn giá trị GẦN ĐÚNG"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "40302198",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1 == 2"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "866394bd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1 == 3"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "e759d92f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.1"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 == 0.2"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "94588ea4",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 + 0.2 == 0.4"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "a2b267df",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 + 0.1 == 0.3"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "a684f11b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.30000000000000004"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 + 0.1"
]
},
{
"cell_type": "markdown",
"id": "90eeb791",
"metadata": {},
"source": [
"https://pymi.vn/blog/why-not-float/"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "15f1357d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1+0.1"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "9680dc5c",
"metadata": {},
"outputs": [],
"source": [
"x = 0.1"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "c67a3120",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3602879701896397, 36028797018963968)"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.as_integer_ratio()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "82540c78",
"metadata": {},
"outputs": [],
"source": [
"y = 0.5"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "9ff39ff3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 2)"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y.as_integer_ratio()"
]
},
{
"cell_type": "markdown",
"id": "09be3517",
"metadata": {},
"source": [
"## không so sánh == với float"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7af8b08",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment