From 69d21498271c110702e73374ca71d79661d3437f Mon Sep 17 00:00:00 2001 From: Phoebox <9744104+phoebox@user.noreply.gitee.com> Date: Sun, 3 Apr 2022 06:21:46 +0000 Subject: [PATCH 1/2] =?UTF-8?q?python=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A+=E7=BC=91=E8=99=B9=E6=98=BE+202122011064?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 202122011064.ipynb | 272 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 202122011064.ipynb diff --git a/202122011064.ipynb b/202122011064.ipynb new file mode 100644 index 0000000..028fb1e --- /dev/null +++ b/202122011064.ipynb @@ -0,0 +1,272 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5852d813", + "metadata": {}, + "source": [ + "作业要求以学号命名,类似\"123456.ipynb\",不需要加姓名。\n", + "\n", + "\n", + "作业提交的方式见下面链接:\n", + "https://blog.csdn.net/sheagu/article/details/122397816" + ] + }, + { + "cell_type": "markdown", + "id": "5d3dca5a", + "metadata": {}, + "source": [ + "## 题目一\n", + "\n", + "有一个这样的DNA核酸序列\n", + "\n", + "“AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC”\n", + "\n", + "请把这个核酸序列存入一个list,并数一数A、G、C、T各有多少个。" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "e6521351", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "腺嘌呤A有20个;\n", + "\n", + "鸟嘌呤G有17个;\n", + "\n", + "胞嘧啶C有12个;\n", + "\n", + "胸腺嘧啶T有21个。\n" + ] + } + ], + "source": [ + "dna_str = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'\n", + "dnas = []\n", + "dnas.extend(dna_str)\n", + "\n", + "def countnums(x):\n", + " num = 0\n", + " n = len(dnas)\n", + " for i in range(0, n):\n", + " if dnas[i] == x :\n", + " num += 1\n", + " else:\n", + " num = num\n", + " return(num)\n", + "\n", + "print('腺嘌呤A有' + str(countnums('A')) + '个;\\n')\n", + "print('鸟嘌呤G有' + str(countnums('G')) + '个;\\n')\n", + "print('胞嘧啶C有' + str(countnums('C')) + '个;\\n')\n", + "print('胸腺嘧啶T有' + str(countnums('T')) + '个。')\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "daf8500d", + "metadata": {}, + "source": [ + "## 题目二\n", + "\n", + "一个花样滑冰运动员表演后,裁判给表演内容进行评分,分数从0.25分到10分,每次增加值为0.25分。\n", + "\n", + "试生成一个元组,把可能的得分存入元组,并遍历元组的每一项,打印“一个运动员可能得_____分”。" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "90604ebb", + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.0, 4.25, 4.5, 4.75, 5.0, 5.25, 5.5, 5.75, 6.0, 6.25, 6.5, 6.75, 7.0, 7.25, 7.5, 7.75, 8.0, 8.25, 8.5, 8.75, 9.0, 9.25, 9.5, 9.75, 10.0)\n", + "\n", + "一个运动员可能得0.25分\n", + "\n", + "一个运动员可能得0.5分\n", + "\n", + "一个运动员可能得0.75分\n", + "\n", + "一个运动员可能得1.0分\n", + "\n", + "一个运动员可能得1.25分\n", + "\n", + "一个运动员可能得1.5分\n", + "\n", + "一个运动员可能得1.75分\n", + "\n", + "一个运动员可能得2.0分\n", + "\n", + "一个运动员可能得2.25分\n", + "\n", + "一个运动员可能得2.5分\n", + "\n", + "一个运动员可能得2.75分\n", + "\n", + "一个运动员可能得3.0分\n", + "\n", + "一个运动员可能得3.25分\n", + "\n", + "一个运动员可能得3.5分\n", + "\n", + "一个运动员可能得3.75分\n", + "\n", + "一个运动员可能得4.0分\n", + "\n", + "一个运动员可能得4.25分\n", + "\n", + "一个运动员可能得4.5分\n", + "\n", + "一个运动员可能得4.75分\n", + "\n", + "一个运动员可能得5.0分\n", + "\n", + "一个运动员可能得5.25分\n", + "\n", + "一个运动员可能得5.5分\n", + "\n", + "一个运动员可能得5.75分\n", + "\n", + "一个运动员可能得6.0分\n", + "\n", + "一个运动员可能得6.25分\n", + "\n", + "一个运动员可能得6.5分\n", + "\n", + "一个运动员可能得6.75分\n", + "\n", + "一个运动员可能得7.0分\n", + "\n", + "一个运动员可能得7.25分\n", + "\n", + "一个运动员可能得7.5分\n", + "\n", + "一个运动员可能得7.75分\n", + "\n", + "一个运动员可能得8.0分\n", + "\n", + "一个运动员可能得8.25分\n", + "\n", + "一个运动员可能得8.5分\n", + "\n", + "一个运动员可能得8.75分\n", + "\n", + "一个运动员可能得9.0分\n", + "\n", + "一个运动员可能得9.25分\n", + "\n", + "一个运动员可能得9.5分\n", + "\n", + "一个运动员可能得9.75分\n", + "\n", + "一个运动员可能得10.0分\n" + ] + } + ], + "source": [ + "score = [0]*40\n", + "for i in range(0,40):\n", + " score[i] = 0.25 + 0.25*i\n", + "scores = tuple(score)\n", + "print(scores)\n", + "\n", + "for j in range(0,40):\n", + " print('\\n一个运动员可能得' + str(scores[j]) + '分')\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "0c3a4e99", + "metadata": {}, + "source": [ + "## 题目三\n", + "\n", + "创建一个字典,列出你所了解的地域美食,比如{'肠粉':{'城市':'广州','原料':'米'}}。当然,你可以做的更丰富一些。\n", + "最后遍历你熟悉的美食,打印出,类似如下的句子:“肠粉是广州的一种美食,它的主要原料是米”。" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "b0026af6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "肉夹馍是西安的一种美食,它的主要原料是面粉和肉,一般加入肉汁作为调料。\n", + "\n", + "热干面是武汉的一种美食,它的主要原料是面粉,一般加入芝麻酱作为调料。\n", + "\n", + "锅包肉是沈阳的一种美食,它的主要原料是面粉和肉,一般加入糖醋作为调料。\n", + "\n", + "麻辣火锅是成都的一种美食,它的主要原料是辣椒、油和各种菜,一般加入芝麻油、芝麻酱等等作为调料。\n" + ] + } + ], + "source": [ + "food_city = {'肉夹馍': {'城市':'西安','原料':'面粉和肉','调料':'肉汁'},\n", + " '热干面': {'城市':'武汉','原料':'面粉','调料':'芝麻酱'},\n", + " '锅包肉': {'城市':'沈阳','原料':'面粉和肉','调料':'糖醋'},\n", + " '麻辣火锅': {'城市':'成都','原料':'辣椒、油和各种菜','调料':'芝麻油、芝麻酱等等'}\n", + " }\n", + "\n", + "for foods_name, foods_information in food_city.items():\n", + " print(\"\\n%s是%s的一种美食,它的主要原料是%s,一般加入%s作为调料。\" % (foods_name.title(), foods_information['城市'], \n", + " foods_information['原料'],foods_information['调料']))\n" + ] + } + ], + "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.9.7" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- Gitee From e3fdcd48b98448083030493d04baf547ce082246 Mon Sep 17 00:00:00 2001 From: Phoebox <9744104+phoebox@user.noreply.gitee.com> Date: Sun, 3 Apr 2022 07:04:04 +0000 Subject: [PATCH 2/2] 202122011094 --- 202122011094.ipynb | 223 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 202122011094.ipynb diff --git a/202122011094.ipynb b/202122011094.ipynb new file mode 100644 index 0000000..414128f --- /dev/null +++ b/202122011094.ipynb @@ -0,0 +1,223 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5852d813", + "metadata": {}, + "source": [ + "作业要求以学号命名,类似\"123456.ipynb\",不需要加姓名。\n", + "\n", + "\n", + "作业提交的方式见下面链接:\n", + "https://blog.csdn.net/sheagu/article/details/122397816" + ] + }, + { + "cell_type": "markdown", + "id": "5d3dca5a", + "metadata": {}, + "source": [ + "## 题目一\n", + "\n", + "有一个这样的DNA核酸序列\n", + "\n", + "“AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC”\n", + "\n", + "请把这个核酸序列存入一个list,并数一数A、G、C、T各有多少个。" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e6521351", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DNA序列中A有20个\n", + "DNA序列中G有17个\n", + "DNA序列中C有12个\n", + "DNA序列中T有21个\n" + ] + } + ], + "source": [ + "# 初始化DNA序列与AGCT的个数\n", + "DNA_str = 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC'\n", + "DNA = []\n", + "DNA.extend(DNA_str)\n", + " \n", + "elements = {'A': 0,\n", + " 'G': 0,\n", + " 'C': 0,\n", + " 'T': 0,\n", + " }\n", + "\n", + "# 计算DNA序列中AGCT的个数 \n", + "for x in DNA:\n", + " for key in elements:\n", + " if x == key:\n", + " elements[key] = elements[key]+1\n", + " break\n", + "\n", + "# 输出DNA序列中AGCT的个数 \n", + "for key, number in elements.items():\n", + " print(\"DNA序列中%s有%d个\" % (key,number))" + ] + }, + { + "cell_type": "markdown", + "id": "daf8500d", + "metadata": {}, + "source": [ + "## 题目二\n", + "\n", + "一个花样滑冰运动员表演后,裁判给表演内容进行评分,分数从0.25分到10分,每次增加值为0.25分。\n", + "\n", + "试生成一个元组,把可能的得分存入元组,并遍历元组的每一项,打印“一个运动员可能得_____分”。" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "90604ebb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "一个运动员可能得0.25分\n", + "一个运动员可能得0.5分\n", + "一个运动员可能得0.75分\n", + "一个运动员可能得1.0分\n", + "一个运动员可能得1.25分\n", + "一个运动员可能得1.5分\n", + "一个运动员可能得1.75分\n", + "一个运动员可能得2.0分\n", + "一个运动员可能得2.25分\n", + "一个运动员可能得2.5分\n", + "一个运动员可能得2.75分\n", + "一个运动员可能得3.0分\n", + "一个运动员可能得3.25分\n", + "一个运动员可能得3.5分\n", + "一个运动员可能得3.75分\n", + "一个运动员可能得4.0分\n", + "一个运动员可能得4.25分\n", + "一个运动员可能得4.5分\n", + "一个运动员可能得4.75分\n", + "一个运动员可能得5.0分\n", + "一个运动员可能得5.25分\n", + "一个运动员可能得5.5分\n", + "一个运动员可能得5.75分\n", + "一个运动员可能得6.0分\n", + "一个运动员可能得6.25分\n", + "一个运动员可能得6.5分\n", + "一个运动员可能得6.75分\n", + "一个运动员可能得7.0分\n", + "一个运动员可能得7.25分\n", + "一个运动员可能得7.5分\n", + "一个运动员可能得7.75分\n", + "一个运动员可能得8.0分\n", + "一个运动员可能得8.25分\n", + "一个运动员可能得8.5分\n", + "一个运动员可能得8.75分\n", + "一个运动员可能得9.0分\n", + "一个运动员可能得9.25分\n", + "一个运动员可能得9.5分\n", + "一个运动员可能得9.75分\n", + "一个运动员可能得10.0分\n" + ] + } + ], + "source": [ + "# 将可能的得分存入元组\n", + "score = 0.25\n", + "scores = []\n", + "while score <= 10:\n", + " scores.append(score)\n", + " score = score + 0.25\n", + "scores = tuple(scores)\n", + "\n", + "# 遍历并输出元组的每一项\n", + "for x in scores:\n", + " print(\"一个运动员可能得\" + str(round(x,2)) + \"分\")" + ] + }, + { + "cell_type": "markdown", + "id": "0c3a4e99", + "metadata": {}, + "source": [ + "## 题目三\n", + "\n", + "创建一个字典,列出你所了解的地域美食,比如{'肠粉':{'城市':'广州','原料':'米'}}。当然,你可以做的更丰富一些。\n", + "最后遍历你熟悉的美食,打印出,类似如下的句子:“肠粉是广州的一种美食,它的主要原料是米”。" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "b0026af6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "肠粉是广州的一种美食,它的主要原料是米;\n", + "海蛎煎是泉州的一种美食,它的主要原料是海蛎;\n", + "糍粑是成都的一种美食,它的主要原料是米;\n" + ] + } + ], + "source": [ + "# 列出地域美食\n", + "foods = {'肠粉':{'城市':'广州','原料':'米'},\n", + " '海蛎煎':{'城市':'泉州','原料':'海蛎'},\n", + " '糍粑':{'城市':'成都','原料':'米'},\n", + " }\n", + "\n", + "# 遍历并打印\n", + "for name, information in foods.items():\n", + " print(name + \"是\" + information['城市'] + \"的一种美食,它的主要原料是\" + information['原料'] + \";\")" + ] + } + ], + "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.9.7" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- Gitee