diff --git a/.gitignore b/.gitignore index 742f63f..ffb2c8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,173 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook .ipynb_checkpoints -.pyc -*#* -*~ -video/* \ No newline at end of file + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +# VSCode +.vscode/ +*.code-workspace + +# OS specific +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/01-variable/questions.ipynb b/01-variable/questions.ipynb index 2e21526..8f8453e 100644 --- a/01-variable/questions.ipynb +++ b/01-variable/questions.ipynb @@ -9,6 +9,26 @@ "* 然后输出 Hi + 姓名" ] }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hi, Witty\n", + "Hi, Witty\n" + ] + } + ], + "source": [ + "name = input('Please input your name')\n", + "print('Hi,', name)\n", + "print('Hi, ' + name)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -28,6 +48,43 @@ " " ] }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Dear, aa:\n", + "Your purchased product: bb is delivered!\n", + "Thanks for you choosing!\n", + "\n" + ] + } + ], + "source": [ + "user_name = input('Please input your name: ')\n", + "product_name = input('Please input your product name: ')\n", + "# 1\n", + "# print('Dear ',username, ':')\n", + "# print('Your purchased product :',productname, 'is delivered!')\n", + "# print('Thanks for your choosing!')\n", + "# 2\n", + "# email_templete=f'''\n", + "# Dear {user_name}:\n", + "# Your purchased product: {product_name} is delivered! \n", + "# Thanks for you choosing!\n", + "# '''\n", + "# 3\n", + "email_templete = '''Dear, %s:\n", + "Your purchased product: %s is delivered!\n", + "Thanks for you choosing!\n", + "'''\n", + "print(email_templete % (user_name,product_name))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -36,6 +93,24 @@ "从 \"You Rise Me Up\" 中截取 Rise" ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Rise\n" + ] + } + ], + "source": [ + "str = 'Your Rise Me Up'\n", + "print(str[4:9])" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -44,6 +119,25 @@ "将 \"Python Basic\" 转成小写" ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "python basic\n" + ] + } + ], + "source": [ + "str = 'Python Basic'\n", + "low_str = str.lower()\n", + "print(low_str)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -53,6 +147,32 @@ "* 打印出结果" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1900000\n" + ] + } + ], + "source": [ + "# 1\n", + "# num = 1000 * 2000 - 1000000\n", + "# print(num)\n", + "\n", + "# 2\n", + "a = 1000\n", + "b = 2000\n", + "c = a * b\n", + "num = c - 100000\n", + "print(num)" + ] + }, { "cell_type": "markdown", "metadata": { @@ -68,6 +188,34 @@ "* print(type(\"Hello\"))" ] }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n" + ] + } + ], + "source": [ + "print(type(100))\n", + "print(type('Hello'))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "1. Int\n", + "2. String" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -82,7 +230,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -96,7 +244,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/02-logic/questions.ipynb b/02-logic/questions.ipynb index 95aecb2..806b9cf 100644 --- a/02-logic/questions.ipynb +++ b/02-logic/questions.ipynb @@ -111,16 +111,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:20:56.871197Z", "start_time": "2020-09-15T07:20:52.153375Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "春季\n" + ] + } + ], "source": [ - "\n" + "month = int(input('Please input the month: '))\n", + "if 1<=month<=3:\n", + " print('春季')\n", + "elif 4<=month<=6: \n", + " print('夏季')\n", + "elif 7<=month<=9:\n", + " print('秋季')\n", + "elif 10<=month<=12:\n", + " print('冬季')\n", + "else:\n", + " print('机器故障!')" ] }, { @@ -157,15 +175,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:20:58.738996Z", "start_time": "2020-09-15T07:20:56.873725Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "系统故障\n" + ] + } + ], + "source": [ + "month=int(input('Please input the month: '))\n", + "if month < 1 or month> 12:\n", + " print('系统故障')\n", + "elif month < 4:\n", + " print('春季')\n", + "elif month < 7:\n", + " print('夏季')\n", + "elif month < 10:\n", + " print('秋季')\n", + "else:\n", + " print('冬季')" + ] }, { "cell_type": "markdown", @@ -201,16 +239,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:20:59.832765Z", "start_time": "2020-09-15T07:20:58.741537Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "夏季\n" + ] + } + ], "source": [ - "\n" + "month = int(input('Please input the month: '))\n", + "if 1<=month and month<=3:\n", + " print('春季')\n", + "elif 4<=month and month<=6: \n", + " print('夏季')\n", + "elif 7<=month and month<=9:\n", + " print('秋季')\n", + "elif 10<=month and month<=12:\n", + " print('冬季')\n", + "else:\n", + " print('机器故障!')\n" ] }, { @@ -253,15 +309,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:21:05.254821Z", "start_time": "2020-09-15T07:20:59.835292Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not aleat\n" + ] + } + ], + "source": [ + "\n", + "commodity = input('Please choose the commodity[A: 100, B: 90, C:80]')\n", + "sales = int(input('Please input the reduce price'))\n", + "if commodity == 'A' and sales> 30:\n", + " print('Alert: ', commodity, sales)\n", + "elif commodity == 'B' and sales>20:\n", + " print('Alert: ', commodity, sales)\n", + "elif commodity == 'C' and sales> 10:\n", + " print('Alert: ', commodity, sales)\n", + "else:\n", + " print('Not aleat')" + ] }, { "cell_type": "markdown", @@ -307,15 +383,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:21:09.261330Z", "start_time": "2020-09-15T07:21:05.256783Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Alert: B 30\n" + ] + } + ], + "source": [ + "commodity = input('Please choose the commodity[A: 100, B: 90, C:80]')\n", + "sales = int(input('Please input the reduce price'))\n", + "if (commodity == 'A' and sales>30) or(commodity == 'B' and sales>20) or (commodity == 'C' and sales> 10) :\n", + " print('Alert: ', commodity, sales)\n", + "else:\n", + " print('Not aleat')" + ] }, { "cell_type": "markdown", @@ -346,15 +437,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:21:11.450273Z", "start_time": "2020-09-15T07:21:09.263112Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "考了59分,要加油呀!\n" + ] + } + ], + "source": [ + "score = int(input('Please input your score: ')) \n", + "if score < 0 or score> 100:\n", + " pass\n", + "elif score< 60:\n", + " print(f'考了{score}分,要加油呀!')\n", + "elif score <80:\n", + " print(f'考了{score}分,不错呀,认真学习了!')\n", + "elif score <=100:\n", + " print(f'考了{score}分,考的不错,不要骄傲!')" + ] }, { "cell_type": "markdown", @@ -384,15 +493,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": { "ExecuteTime": { "end_time": "2020-09-15T07:21:16.073203Z", "start_time": "2020-09-15T07:21:11.452151Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "太热了,开冷空调了\n" + ] + } + ], "source": [ + "season = input('请输入季节:【winter or summer】 ')\n", + "temperature = int(input('请输入今天的温度:'))\n", + "if season == 'winter' and temperature < 10:\n", + " print('太冷了,开热空调了')\n", + "if season == 'summer' and temperature> 27:\n", + " print('太热了,开冷空调了')\n", "\n" ] }, @@ -413,7 +536,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -427,7 +550,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/03-loop/answer-questions.ipynb b/03-loop/answer-questions.ipynb index aad427b..ac6c840 100644 --- a/03-loop/answer-questions.ipynb +++ b/03-loop/answer-questions.ipynb @@ -211,14 +211,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-09-16T02:54:43.089949Z", "start_time": "2020-09-16T02:54:43.086482Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ">> For循环运算后: i:1, total:1\n", + ">> For循环运算后: i:2, total:2\n", + ">> For循环运算后: i:3, total:6\n", + ">> For循环运算后: i:4, total:24\n", + "连乘结果: 24\n" + ] + } + ], "source": [ "total = 1\n", "for i in range(1,5):\n", @@ -266,14 +278,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-07-14T02:05:46.643010Z", "start_time": "2020-07-14T02:05:46.629372Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "G\n", + "o\n", + "o\n", + "d\n", + " \n", + "D\n", + "a\n", + "y\n", + "!\n" + ] + } + ], "source": [ "title = \"Good Day!\"\n", "for char in title:\n", @@ -657,7 +685,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -671,7 +699,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/03-loop/questions.ipynb b/03-loop/questions.ipynb index b113c38..b4349ce 100644 --- a/03-loop/questions.ipynb +++ b/03-loop/questions.ipynb @@ -112,15 +112,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-07-14T02:03:21.498180Z", "start_time": "2020-07-14T02:03:21.495062Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1月\n", + "2月\n", + "3月\n", + "4月\n", + "5月\n", + "6月\n", + "7月\n", + "8月\n", + "9月\n", + "10月\n", + "11月\n", + "12月\n" + ] + } + ], + "source": [ + "for i in range(1,13):\n", + " print('%d月' % i)" + ] }, { "cell_type": "markdown", @@ -150,7 +172,10 @@ } }, "outputs": [], - "source": [] + "source": [ + "for i in range(1,13):\n", + " print(i,'月')" + ] }, { "cell_type": "markdown", @@ -204,15 +229,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-09-16T02:54:43.089949Z", "start_time": "2020-09-16T02:54:43.086482Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 的阶乘是:1\n", + "2 的阶乘是:2\n", + "3 的阶乘是:6\n", + "4 的阶乘是:24\n" + ] + } + ], + "source": [ + "total = 1\n", + "for i in range(1,5):\n", + " total *= i\n", + " print('%d 的阶乘是:%d' % (i,total))" + ] }, { "cell_type": "markdown", @@ -251,15 +292,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-07-14T02:05:46.643010Z", "start_time": "2020-07-14T02:05:46.629372Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "G\n", + "o\n", + "o\n", + "d\n", + " \n", + "D\n", + "a\n", + "y\n", + "!\n" + ] + } + ], + "source": [ + "str = 'Good Day!'\n", + "for i in str:\n", + " print(i)" + ] }, { "cell_type": "markdown", @@ -315,15 +376,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-07-14T02:06:20.403775Z", "start_time": "2020-07-14T02:06:20.400623Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]\n" + ] + } + ], + "source": [ + "even=[]\n", + "for i in range(0,51):\n", + " if i % 2 == 0:\n", + " even.append(i)\n", + "print(even)" + ] }, { "cell_type": "markdown", @@ -375,20 +450,37 @@ } }, "outputs": [], - "source": [] + "source": [ + "even = []\n", + "for i in range(0,51,2):\n", + " even.append(i)\n", + "print(even)" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-09-16T03:33:03.268983Z", "start_time": "2020-09-16T03:33:03.265051Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "list(range(0,5,2))" + "# list(range(0,5,2))\n", + "list(range(0,50,3))" ] }, { @@ -440,28 +532,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-09-16T04:02:22.463395Z", "start_time": "2020-09-16T04:02:22.459880Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "2\n", + "1\n" + ] + } + ], + "source": [ + "rating = [3,5,4,2,1,5,5]\n", + "for i in rating:\n", + " if i>= 4:\n", + " continue\n", + " print(i)" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2020-09-16T04:13:47.930011Z", "start_time": "2020-09-16T04:13:47.926934Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "2\n", + "1\n" + ] + } + ], "source": [ "# 不用continue,理解即可\n", + "stars = [3,5,4,2,1,5,5]\n", "for star in stars:\n", " if star < 4:\n", " print(star)" @@ -585,15 +704,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2020-09-16T07:42:46.446010Z", "start_time": "2020-09-16T06:41:42.597043Z" } }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Dear aa,\n", + "Your purchased product: bb is delivered!\n", + "Thanks for you choosing!\n", + "\n", + "=============\n", + "\n", + "Dear cc,\n", + "Your purchased product: dd is delivered!\n", + "Thanks for you choosing!\n", + "\n", + "=============\n" + ] + } + ], + "source": [ + "email_body = '''\n", + "Dear %s,\n", + "Your purchased product: %s is delivered!\n", + "Thanks for you choosing!\n", + "'''\n", + "while True:\n", + " name = input('请输出名称:')\n", + " if name == '!':\n", + " break\n", + " product = input('请输入产品名: ')\n", + " print(email_body % (name, product))\n", + " print('=============')\n", + "\n", + "\n" + ] }, { "cell_type": "markdown", @@ -607,7 +760,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -621,7 +774,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/04-list-dict/questions.ipynb b/04-list-dict/questions.ipynb index 01d2116..98044e8 100644 --- a/04-list-dict/questions.ipynb +++ b/04-list-dict/questions.ipynb @@ -180,7 +180,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -189,20 +189,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "进行升序排序\n", + "[10, 20, 50, 100, 200, 300, 500, 1000]\n" + ] + } + ], "source": [ - "print(\"进行升序排序\")\n" + "print(\"进行升序排序\")\n", + "sales.sort()\n", + "print(sales)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "进行降序排序\n", + "[1000, 500, 300, 200, 100, 50, 20, 10]\n" + ] + } + ], "source": [ - "print(\"进行降序排序\")\n" + "print(\"进行降序排序\")\n", + "sales.sort(reverse=True)\n", + "print(sales)\n" ] }, { @@ -217,16 +239,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "查看最后3个数据(top3)\n", + "[300, 500, 1000]\n" + ] + } + ], "source": [ - "print(\"查看最后3个数据(top3)\")\n" + "print(\"查看最后3个数据(top3)\")\n", + "sales.sort()\n", + "print(sales[-3:])\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-07-16T10:18:33.737309Z", @@ -238,22 +271,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "进行升序排序\n", - "[10, 20, 50, 100, 200, 300, 500, 1000]\n", - "----------------------------------------------------------------------\n", - "进行降序排序\n", - "[1000, 500, 300, 200, 100, 50, 20, 10]\n", - "----------------------------------------------------------------------\n", - "查看最后3个数据(top3)\n", - "[300, 500, 1000]\n", - "----------------------------------------------------------------------\n", "查看最前3个数据( 最低的3个销售额)\n", "[10, 20, 50]\n" ] } ], "source": [ - "print(\"查看最前3个数据( 最低的3个销售额)\")\n" + "print(\"查看最前3个数据( 最低的3个销售额)\")\n", + "sales.sort()\n", + "print(sales[:3])\n" ] }, { @@ -305,38 +331,94 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ - "print(\"现有新来了一辆车 'A0030', 请把它放在 car_nums 的最后面\")\n" + "car_nums = ['A0001','A00X9','A0027'] \n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "现有新来了一辆车 'A0030', 请把它放在 car_nums 的最后面\n", + "['A0001', 'A00X9', 'A0027', 'A0030']\n" + ] + } + ], "source": [ - "print(\"现有新来了一辆车 'A0000', 请把它放在 car_nums 的最前面\")\n" + "print(\"现有新来了一辆车 'A0030', 请把它放在 car_nums 的最后面\")\n", + "car_nums.append('A0030')\n", + "print(car_nums)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "现有新来了一辆车 'A0000', 请把它放在 car_nums 的最前面\n", + "['A0000', 'A0001', 'A00X9', 'A0027']\n" + ] + } + ], "source": [ - "print(\"'A00X9' 这辆车现在不租你的停车位上,请把它从 car_nums 中删掉\")\n" + "print(\"现有新来了一辆车 'A0000', 请把它放在 car_nums 的最前面\")\n", + "car_nums.insert(0,'A0000')\n", + "print(car_nums)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'A00X9' 这辆车现在不租你的停车位上,请把它从 car_nums 中删掉\n", + "2\n", + "['A0000', 'A0001', 'A0027']\n" + ] + } + ], "source": [ - "print(\"现在来了一个车队 ['B0001','B0002','B003'], 请用一行代码把它加到 car_nums 中\")\n" + "print(\"'A00X9' 这辆车现在不租你的停车位上,请把它从 car_nums 中删掉\")\n", + "index=car_nums.index('A00X9')\n", + "print(index)\n", + "del car_nums[index]\n", + "print(car_nums)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "现在来了一个车队 ['B0001','B0002','B003'], 请用一行代码把它加到 car_nums 中\n", + "['A0001', 'A00X9', 'A0027', 'B0001', 'B0002', 'B003']\n" + ] + } + ], + "source": [ + "print(\"现在来了一个车队 ['B0001','B0002','B003'], 请用一行代码把它加到 car_nums 中\")\n", + "car_nums.extend(['B0001','B0002','B003'])\n", + "print(car_nums)\n" ] }, { @@ -411,7 +493,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2020-10-09T08:49:42.172498Z", @@ -437,9 +519,24 @@ "start_time": "2020-10-09T08:54:48.298Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "您选的商品SKU-A的价格是100\n", + "您选的商品SKU-D的价格是200\n" + ] + } + ], "source": [ - "# 开始写 while True 循环\n" + "# 开始写 while True 循环\n", + "while True:\n", + " sku=input('请输入sku:')\n", + " if sku == '!':\n", + " break\n", + " price = prices.get(sku)\n", + " print('您选的商品%s的价格是%s: 1' % (sku,price))" ] }, { @@ -557,7 +654,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -571,47 +668,118 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请统计仓库的物品总数量(quantity)\n", + "{'sku': 'SKU-A', 'quantity': 100}\n", + "{'sku': 'SKU-B', 'quantity': 200}\n", + "{'sku': 'SKU-C', 'quantity': 400}\n", + "{'sku': 'SKU-D', 'quantity': 300}\n", + "1000\n" + ] + } + ], "source": [ - "print(\"请统计仓库的物品总数量(quantity)\")\n" + "print(\"请统计仓库的物品总数量(quantity)\")\n", + "total_quantity = 0\n", + "for i in total:\n", + " print(i)\n", + " total_quantity += i['quantity']\n", + "print(total_quantity)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "现在 SKU-A 要入库 100件商品,请更新 SKU-A 的库存记录\n", + "[{'sku': 'SKU-A', 'quantity': 200}, {'sku': 'SKU-B', 'quantity': 200}, {'sku': 'SKU-C', 'quantity': 400}, {'sku': 'SKU-D', 'quantity': 300}]\n" + ] + } + ], "source": [ - "print(\"现在 SKU-A 要入库 100件商品,请更新 SKU-A 的库存记录\")\n" + "print(\"现在 SKU-A 要入库 100件商品,请更新 SKU-A 的库存记录\")\n", + "\n", + "for i in total:\n", + " if i['sku'] == 'SKU-A':\n", + " i['quantity'] += 100\n", + "print(total)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "现在 SKU-E 新品上市,要入库300件商品,请在 total 中新增一条相应记录\n", + "[{'sku': 'SKU-A', 'quantity': 100}, {'sku': 'SKU-B', 'quantity': 200}, {'sku': 'SKU-C', 'quantity': 400}, {'sku': 'SKU-D', 'quantity': 300}, {'sku': 'SKU-E', 'quantity': 300}]\n" + ] + } + ], "source": [ - "print(\"现在 SKU-E 新品上市,要入库300件商品,请在 total 中新增一条相应记录\")\n" + "print(\"现在 SKU-E 新品上市,要入库300件商品,请在 total 中新增一条相应记录\")\n", + "sku_e = {'sku': 'SKU-E', 'quantity': 300}\n", + "total.append(sku_e)\n", + "print(total)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "现在 SKU-B 要退市,请将 SKU-B 这行记录删掉\n", + "[{'sku': 'SKU-C', 'quantity': 400}, {'sku': 'SKU-D', 'quantity': 300}]\n" + ] + } + ], "source": [ - "print(\"现在 SKU-B 要退市,请将 SKU-B 这行记录删掉\")\n" + "print(\"现在 SKU-B 要退市,请将 SKU-B 这行记录删掉\")\n", + "index=0\n", + "for i in total:\n", + " if i['sku'] =='SKU-B':\n", + " total.remove(i)\n", + "\n", + "print(total)\n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "使用切片方法显示 total 中的最后一行记录\n", + "{'sku': 'SKU-E', 'quantity': 300}\n" + ] + } + ], "source": [ - "print(\"使用切片方法显示 total 中的最后一行记录\")\n" + "print(\"使用切片方法显示 total 中的最后一行记录\")\n", + "last_row=total[-1]\n", + "print(last_row)\n" ] }, { @@ -626,7 +794,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -640,7 +808,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/05-function/questions.ipynb b/05-function/questions.ipynb index 5d8a2f8..a390b63 100644 --- a/05-function/questions.ipynb +++ b/05-function/questions.ipynb @@ -189,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-07-14T09:36:17.418139Z", @@ -203,32 +203,40 @@ "text": [ "\n", " Dear Pony:\n", - "\n", - " Your purchased product : MacBook is delivered!\n", - "\n", + " Your purchased product: MacBook is delivered!\n", " Thanks for your choosing!\n", " \n", - "----------Mail Delivered!--------------------\n", "\n", " Dear Bill:\n", - "\n", - " Your purchased product : AirPods is delivered!\n", - "\n", + " Your purchased product: AirPods is delivered!\n", " Thanks for your choosing!\n", " \n", - "----------Mail Delivered!--------------------\n", "\n", " Dear Hank:\n", - "\n", - " Your purchased product : iPhone is delivered!\n", - "\n", + " Your purchased product: iPhone is delivered!\n", " Thanks for your choosing!\n", - " \n", - "----------Mail Delivered!--------------------\n" + " \n" ] } ], "source": [ + "orders = [\n", + " {\"buyer_name\": \"Pony\",\"product\": \"MacBook\"},\n", + " {\"buyer_name\": \"Bill\",\"product\": \"AirPods\"},\n", + " {\"buyer_name\": \"Hank\",\"product\": \"iPhone\"}\n", + "]\n", + "def deliver_mail():\n", + " email_temp='''\n", + " Dear %s:\n", + " Your purchased product: %s is delivered!\n", + " Thanks for your choosing!\n", + " '''\n", + " for i in orders:\n", + " name = i['buyer_name']\n", + " product = i['product']\n", + " print(email_temp % (name,product))\n", + " \n", + "deliver_mail()\n", "\n" ] }, @@ -278,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-07-14T09:44:35.784968Z", @@ -290,14 +298,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "autosum(3): 6\n", - "autosum(10): 55\n", - "autosum(100): 5050\n" + "auto_sum(3): 6\n", + "auto_sum(10): 55\n", + "auto_sum(100): 5050\n" ] } ], "source": [ "# 请在这里做题\n", + "def auto_sum(max_num):\n", + " total = 0\n", + " max_num=int(max_num)\n", + " for i in range(max_num + 1):\n", + " total += i\n", + " return total\n", + "\n", + "# auto_sum(4)\n", + "\n", "\n", "\n", "#\n", @@ -341,7 +358,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-10-12T04:32:05.217681Z", @@ -361,6 +378,8 @@ ], "source": [ "# 请在这里做题\n", + "def auto_sum(max_num):\n", + " return sum(range(max_num+1))\n", "\n", "#\n", "\n", @@ -424,7 +443,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2020-07-18T00:06:52.395838Z", @@ -436,15 +455,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "outeven(3): [0, 2]\n", - "outeven(10): [0, 2, 4, 6, 8, 10]\n", - "outeven(100): [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n" + "out_even(3): [0, 2]\n", + "out_even(10): [0, 2, 4, 6, 8, 10]\n", + "out_even(100): [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n" ] } ], "source": [ "# 请在这里做题\n", - "\n", + "# def out_even(max_num):\n", + "# li=[]\n", + "# for i in range(max_num+1):\n", + "# if i % 2 ==0:\n", + "# li.append(i)\n", + "# return li\n", + "\n", + "def out_even(max_num):\n", + " li=[]\n", + " for i in range(0,max_num+1,2):\n", + " li.append(i)\n", + " return li\n", "#\n", "print(\"out_even(3):\",out_even(3)) \n", "print(\"out_even(10):\",out_even(10)) \n", @@ -494,7 +524,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2020-10-12T04:34:22.835659Z", @@ -514,6 +544,8 @@ ], "source": [ "# 请在这里做题\n", + "def out_even(max_num):\n", + " return list(range(0,max_num+1,2))\n", "\n", "#\n", "\n", @@ -534,7 +566,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -548,7 +580,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/06-class-object/questions.ipynb b/06-class-object/questions.ipynb index 538a2f3..df21715 100644 --- a/06-class-object/questions.ipynb +++ b/06-class-object/questions.ipynb @@ -101,15 +101,103 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " to pony@qq.com\n", + " Dear Pony:\n", + " Your purchased product : MacBook is delivered!\n", + " Thanks for your choosing!\n", + " \n", + "======================================================================\n", + "\n", + " to 13812341234\n", + " Dear Pony:\n", + " Your purchased product : MacBook is delivered!\n", + " Thanks for your choosing!\n", + " \n", + "======================================================================\n", + "\n", + " to bill@ms.com\n", + " Dear Bill:\n", + " Your purchased product : AirPods is delivered!\n", + " Thanks for your choosing!\n", + " \n", + "======================================================================\n", + "\n", + " to 13812341235\n", + " Dear Bill:\n", + " Your purchased product : AirPods is delivered!\n", + " Thanks for your choosing!\n", + " \n", + "======================================================================\n", + "\n", + " to hank@xyz.com\n", + " Dear Hank:\n", + " Your purchased product : iPhone is delivered!\n", + " Thanks for your choosing!\n", + " \n", + "======================================================================\n", + "\n", + " to 13812341239\n", + " Dear Hank:\n", + " Your purchased product : iPhone is delivered!\n", + " Thanks for your choosing!\n", + " \n", + "======================================================================\n" + ] + } + ], + "source": [ + "class Order:\n", + " def __init__(self, email, buyer_name, product, phone):\n", + " self.email = email\n", + " self.buyer_name = buyer_name\n", + " self.product = product\n", + " self.phone = phone\n", + "\n", + " def deliver_mail(self):\n", + " email_temp = '''\n", + " to %s\n", + " Dear %s:\n", + " Your purchased product : %s is delivered!\n", + " Thanks for your choosing!\n", + " '''\n", + " print(email_temp % (self.email, self.buyer_name, self.product))\n", + " print('=' * 70)\n", + "\n", + " def deliver_sms(self):\n", + " sms_temp = '''\n", + " to %s\n", + " Dear %s:\n", + " Your purchased product : %s is delivered!\n", + " Thanks for your choosing!\n", + " '''\n", + " print(sms_temp % (self.phone, self.buyer_name, self.product))\n", + " print('=' * 70)\n", + "\n", + "\n", + "orders = [\n", + " {\"buyer_name\": \"Pony\", \"product\": \"MacBook\", \"email\": \"pony@qq.com\", \"phone\": \"13812341234\"},\n", + " {\"buyer_name\": \"Bill\", \"product\": \"AirPods\", \"email\": \"bill@ms.com\", \"phone\": \"13812341235\"},\n", + " {\"buyer_name\": \"Hank\", \"product\": \"iPhone\", \"email\": \"hank@xyz.com\", \"phone\": \"13812341239\"},\n", + "]\n", + "\n", + "for order in orders:\n", + " sales_obj = Order(order['email'], order['buyer_name'], order['product'], order['phone'])\n", + " sales_obj.deliver_mail()\n", + " sales_obj.deliver_sms()" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".env", "language": "python", "name": "python3" }, @@ -123,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.6" }, "toc": { "base_numbering": 1, diff --git a/exercise.py b/exercise.py new file mode 100644 index 0000000..e0879d0 --- /dev/null +++ b/exercise.py @@ -0,0 +1,11 @@ +# 邮件机器人 +username = input('Please input your name: ') +productname = input('Please input your product name: ') +# print('Dear ',username, ':') +# print('Your purchased product :',productname, 'is delivered!') +# print('Thanks for your choosing!') +print(f''' +Dear {username}: +Your purchased product: {productname} is delivered! +Thanks for you choosing! +''') \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /