Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created October 19, 2022 02:48
Show Gist options
  • Save hvnsweeting/6cf6c32da3d330796c729fa38eb2396d to your computer and use it in GitHub Desktop.
Save hvnsweeting/6cf6c32da3d330796c729fa38eb2396d to your computer and use it in GitHub Desktop.
Học lập trình Python 2022 tại Hà Nội, Sài gòn livestream lớp PYMI2210
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "4d754dc5",
"metadata": {},
"source": [
"# Welcome to pymi!"
]
},
{
"cell_type": "markdown",
"id": "dde1e102",
"metadata": {},
"source": [
"### projecteuler.net 1"
]
},
{
"cell_type": "markdown",
"id": "6f9523cd",
"metadata": {},
"source": [
"\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": 3,
"id": "320dad1e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"233168"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(i for i in range(0, 1000) if i % 3 == 0 or i % 5 == 0)"
]
},
{
"cell_type": "markdown",
"id": "a8b184e6",
"metadata": {},
"source": [
"## tài liệu"
]
},
{
"cell_type": "markdown",
"id": "13dbd7b4",
"metadata": {},
"source": [
"https://docs.python.org/3/"
]
},
{
"cell_type": "markdown",
"id": "0a42ffd0",
"metadata": {},
"source": [
"## cách học"
]
},
{
"cell_type": "markdown",
"id": "f56cfa67",
"metadata": {},
"source": [
"- không ghi chép\n",
"- tập trung gõ, thử nghiệm"
]
},
{
"cell_type": "markdown",
"id": "537126f8",
"metadata": {},
"source": [
"## bật python"
]
},
{
"cell_type": "markdown",
"id": "9020e9bd",
"metadata": {},
"source": [
"python3 "
]
},
{
"cell_type": "markdown",
"id": "400d56d6",
"metadata": {},
"source": [
"```py\n",
"$ python3 \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",
">>> \n"
]
},
{
"cell_type": "markdown",
"id": "d8c0c419",
"metadata": {},
"source": [
"### `>>>` - prompt"
]
},
{
"cell_type": "markdown",
"id": "79134135",
"metadata": {},
"source": [
"chờ nhập phép tính, enter thì hienej kêt quả ở dòng sau "
]
},
{
"cell_type": "markdown",
"id": "8677a3a4",
"metadata": {},
"source": [
"## phép cộng - addition"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "764fd9ef",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d31d3f05",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 + 2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c220869c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"225324"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"213012 + 12312"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0dd7604e",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers (3723730088.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/tmp/ipykernel_367206/3723730088.py\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m 01111+1111\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers\n"
]
}
],
"source": [
"01111+1111"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "b87ac79f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"48764183274618362378601371343831726014533"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"48764183274618327647316478126347813264721 + 34731284893217483912749812"
]
},
{
"cell_type": "markdown",
"id": "e755e4c2",
"metadata": {},
"source": [
"## lớp kết luận: cộng thoải mái"
]
},
{
"cell_type": "markdown",
"id": "321f9890",
"metadata": {},
"source": [
"## phép trừ - subtract"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "7fd8a95f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-12191"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"123 - 12314"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "723c5123",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11111111111111111111111111109878888888888888888888888888888888888888888888888888888889"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111 -1232222222222222222222222222222222222222222222222222222222"
]
},
{
"cell_type": "markdown",
"id": "0b272142",
"metadata": {},
"source": [
"## trừ thoải mái "
]
},
{
"cell_type": "markdown",
"id": "0055eaf9",
"metadata": {},
"source": [
"## nhân - multiply * "
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "66b4ed05",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 * 5"
]
},
{
"cell_type": "markdown",
"id": "fce17a37",
"metadata": {},
"source": [
"### nhân thoải mái "
]
},
{
"cell_type": "markdown",
"id": "fa788157",
"metadata": {},
"source": [
"## phép chia - division\n",
"## / - slash"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "1bdddd7f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.5"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 / 2"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "fec509e9",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4/2"
]
},
{
"cell_type": "markdown",
"id": "4886be0b",
"metadata": {},
"source": [
"4/2 được 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b599620",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9609a0ef",
"metadata": {},
"source": [
"## \\ - backslash"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20a7b7f1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "8c17dae1",
"metadata": {},
"source": [
"## chia thoải mái"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "be6e6da7",
"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/tmp/ipykernel_367206/2590173015.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m6\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": [
"6/0"
]
},
{
"cell_type": "markdown",
"id": "965e3aad",
"metadata": {},
"source": [
"### 6 chia 0 xảy ra Exception ZeroDivisionError"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2fbc3425",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"id": "a717c086",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4/2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "c6bd9114",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1+1"
]
},
{
"cell_type": "markdown",
"id": "0ccc5f85",
"metadata": {},
"source": [
"## type - kiểu dữ liệu"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "d512217c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2)"
]
},
{
"cell_type": "markdown",
"id": "3870fe07",
"metadata": {},
"source": [
"## int - integer"
]
},
{
"cell_type": "markdown",
"id": "06b78ec7",
"metadata": {},
"source": [
"/ˈɪn.tɪ.dʒər/ /ˈɪn.tə.dʒɚ/"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "e75b93cf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2.0)"
]
},
{
"cell_type": "markdown",
"id": "673f9d50",
"metadata": {},
"source": [
"## cache /kæʃ/ - cash"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23f53d8c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "69184751",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "459d35ba",
"metadata": {},
"source": [
"## sort /sɔːt/"
]
},
{
"cell_type": "markdown",
"id": "376d3f1f",
"metadata": {},
"source": [
"## resort /rɪˈzɔːt/"
]
},
{
"cell_type": "markdown",
"id": "b7305547",
"metadata": {},
"source": [
"## suit"
]
},
{
"cell_type": "markdown",
"id": "f657a3d1",
"metadata": {},
"source": [
"## suite - sweet"
]
},
{
"cell_type": "markdown",
"id": "48796468",
"metadata": {},
"source": [
"https://dictionary.cambridge.org/dictionary/english/sort"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c0e0656",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "7c30a747",
"metadata": {},
"source": [
"## float /fləʊt/ /floʊt/"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "8f754b59",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(2.2)"
]
},
{
"cell_type": "markdown",
"id": "ba0af627",
"metadata": {},
"source": [
"## số thực "
]
},
{
"cell_type": "markdown",
"id": "6d34e125",
"metadata": {},
"source": [
"(số hữu tỷ ) + (số vô tỷ)"
]
},
{
"cell_type": "markdown",
"id": "40f1a327",
"metadata": {},
"source": [
"## số hữu tỷ - có tỷ lệ \n",
"## có thể viết ở dạng phân sô"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "fc89a554",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3333333333333333"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1/3"
]
},
{
"cell_type": "markdown",
"id": "82b6f901",
"metadata": {},
"source": [
"## số vô tỷ- không tỷ lệ\n",
"## không biểu diễn được ở dạng phân số"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "fe1d6eea",
"metadata": {},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "36920747",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.141592653589793"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.pi"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "99d4cbe6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.4142135623730951"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"math.sqrt(2)"
]
},
{
"cell_type": "markdown",
"id": "cd694bab",
"metadata": {},
"source": [
"## float là kiểu dữ liệu gần đúng"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "f83b35f2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1.0"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "db4afc02",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "c0f045d4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"0.1 + 0.1 == 0.2"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "4d6db28d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1 == 2"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "64939fe2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1 == 3"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "fc630533",
"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": "f5ffb415",
"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": "607912fe",
"metadata": {},
"source": [
"https://pymi.vn/blog/why-not-float/"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "51d94db2",
"metadata": {},
"outputs": [],
"source": [
"x = 0.1"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "6a477843",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3602879701896397, 36028797018963968)"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x.as_integer_ratio()"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "e15ff4a0",
"metadata": {},
"outputs": [],
"source": [
"y = 0.3"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "023fd532",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(5404319552844595, 18014398509481984)"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y.as_integer_ratio()"
]
},
{
"cell_type": "markdown",
"id": "be4751d5",
"metadata": {},
"source": [
"## không so sánh == float"
]
},
{
"cell_type": "markdown",
"id": "b06e14d0",
"metadata": {},
"source": [
"https://docs.python.org/3/tutorial/floatingpoint.html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa6df9d6",
"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