diff --git a/19-22/readme.md b/19-22/readme.md new file mode 100644 index 00000000..b0b906d3 --- /dev/null +++ b/19-22/readme.md @@ -0,0 +1 @@ +# 晚上19:00-22:00上课的同学,作业目录 diff --git a/8-10/201711680007/.add b/8-10/201711680007/.add new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/8-10/201711680007/.add @@ -0,0 +1 @@ + diff --git a/8-10/201711680007/1.ipynb b/8-10/201711680007/1.ipynb new file mode 100644 index 00000000..12f8f68c --- /dev/null +++ b/8-10/201711680007/1.ipynb @@ -0,0 +1,147 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入数字后按下enter进入下一过程8\n", + "数的阶乘 40320\n" + ] + } + ], + "source": [ + "#n的阶乘\n", + "n=int(input('请输入数字后按下enter进入下一过程'))\n", + "total=1\n", + "i=1\n", + "while i < n:\n", + " i=i+1\n", + " total=total*i\n", + "print('数的阶乘',total)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入整数个数3\n", + "请输入整数2\n", + "请输入整数3\n", + "请输入整数1\n", + "数值之和 6\n" + ] + } + ], + "source": [ + "#由用户指定整数个数,并由用户输入多个整数,并求和\n", + "n=int(input(\"请输入整数个数\"))\n", + "i=0\n", + "total=0\n", + "while i < n:\n", + " m=int(input(\"请输入整数\"))\n", + " i=i+1\n", + " total=total+m\n", + "print('数值之和',total)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。3\n", + "请输入一个正整数4\n", + "请输入一个正整数2\n", + "请输入一个正整数9\n", + "请输入一个正整数20\n", + "21 648\n" + ] + } + ], + "source": [ + " #用户可以输入的任意多个数字,直到: 输入所有数字的和比当前输入数字小,且输入所有数字的积大于500\n", + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "total=n\n", + "product=n\n", + "while n<=total and product<=500:\n", + " total=total+n\n", + " product=product*n\n", + " n=int(input('请输入一个正整数'))\n", + "print(total,product)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入0之外任意整数,如果结束请输入04\n", + "4\n", + "请输入0之外任意整数,如果结束请输入00\n", + "结束\n" + ] + } + ], + "source": [ + "#用户可以输入的任意多个数字,直到用户不想输入为止。\n", + "a=0\n", + "b=1\n", + "while a1:\n", + " n=int(input('请输入你想输入的数字,以回车结束。'))" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你想输入的数字,以回车结束。66\n", + "请继续输入你想输入的数字,以回车结束。88\n", + "请继续输入你想输入的数字,以回车结束。8787878\n" + ] + } + ], + "source": [ + "n=int(input('请输入你想输入的数字,以回车结束。'))\n", + "total=0\n", + "product=1\n", + "\n", + "while total>=n or product<=500: \n", + " total=total+n\n", + " product=product*n \n", + " n=int(input('请继续输入你想输入的数字,以回车结束。'))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201711680071/3.ipynb b/8-10/201711680071/3.ipynb new file mode 100644 index 00000000..509cfdd2 --- /dev/null +++ b/8-10/201711680071/3.ipynb @@ -0,0 +1,98 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个数字,回车结束。3\n", + "请输入一个数字,回车结束。4\n", + "请选择你想对这两个数进行的运算:求和请输入1、求积请输入2、求余请输入3,否则将自动整除。2\n", + "12\n" + ] + } + ], + "source": [ + "m=int(input('请输入一个数字,回车结束。'))\n", + "n=int(input('请输入一个数字,回车结束。'))\n", + "i=int(input('请选择你想对这两个数进行的运算:求和请输入1、求积请输入2、求余请输入3,否则将自动整除。'))\n", + "\n", + "if i==1:\n", + " total=m+n\n", + " print(total)\n", + "elif i==2:\n", + " product=m*n\n", + " print(product)\n", + "elif i==3:\n", + " remainder=m%n\n", + " print(remainder)\n", + "else :\n", + " divide=m/n\n", + " print(divide)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个英文名词(单数形式)watch\n", + "请在词尾加上es\n" + ] + } + ], + "source": [ + "i=input('请输入一个英文名词(单数形式)')\n", + "\n", + "if i.endswith ('s'):\n", + " print('请在词尾加上es')\n", + "elif i.endswith ('x'):\n", + " print('请在词尾加上es')\n", + "elif i.endswith ('z'):\n", + " print('请在词尾加上es')\n", + "elif i.endswith ('sh'):\n", + " print('请在词尾加上es')\n", + "elif i.endswith ('ch'):\n", + " print('请在词尾加上es')\n", + "elif i.endswith ('f'):\n", + " print('请在词尾加s之前先把f变 ve')\n", + "elif i.endswith ('fe'):\n", + " print('请在词尾加s之前先把fe变 ve')\n", + "elif i.endswith ('y'):\n", + " print('请把y变i再加es')\n", + "elif i.endswith!='s':\n", + " print('请在词尾加上s')\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201711680109/2.ipynb b/8-10/201711680109/2.ipynb new file mode 100644 index 00000000..68ba7bde --- /dev/null +++ b/8-10/201711680109/2.ipynb @@ -0,0 +1,180 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束4\n", + "24\n" + ] + } + ], + "source": [ + "n=int(input('请输入一个正整数,以回车结束'))\n", + "i=0\n", + "total=1\n", + "while i=n or p<=500:\n", + " total=total+n\n", + " p=p*n\n", + " n=int(input('请输入你想输入的数字,以回车结束。'))\n", + "print('再见',name)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的名字,以回车结束。张伊晗\n", + "你好 张伊晗\n", + "请输入你想输入的数字,以回车结束。2\n", + "请输入你想输入的数字,以回车结束。3\n", + "请输入你想输入的数字,以回车结束。4\n", + "请输入你想输入的数字,以回车结束。5\n", + "请输入你想输入的数字,以回车结束。6\n", + "请输入你想输入的数字,以回车结束。22\n" + ] + } + ], + "source": [ + "name=input('请输入你的名字,以回车结束。')\n", + "print('你好',name)\n", + "n=int(input('请输入你想输入的数字,以回车结束。'))\n", + "i=0\n", + "while i<1:\n", + " n=int(input('请输入你想输入的数字,以回车结束。'))\n", + "\n", + " \n", + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201711680109/3.ipynb b/8-10/201711680109/3.ipynb new file mode 100644 index 00000000..028e2b52 --- /dev/null +++ b/8-10/201711680109/3.ipynb @@ -0,0 +1,134 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数,以回车结束。7\n", + "请输入一个非零整数,以回车结束。2\n", + "求和请输入1,乘积请输入2,求余数请输入3,都不需要请输入其他任意数字,以回车结束。4\n", + "3\n" + ] + } + ], + "source": [ + "m=int(input('请输入一个整数,以回车结束。'))\n", + "n=int(input('请输入一个非零整数,以回车结束。'))\n", + "o=int(input('求和请输入1,乘积请输入2,求余数请输入3,都不需要请输入其他任意数字,以回车结束。'))\n", + "s=2*m\n", + "if o==1:\n", + " if mn:\n", + " \n", + " i=0\n", + " p=m-n\n", + " q=0\n", + " while in:\n", + " i=0\n", + " p=m-n\n", + " s=n\n", + " q=n\n", + " while ii:\n", + " n=int(input('请输入一个正整数'))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "n = int(input('请输入一个整数,回车结束'))\n", + "total=n\n", + "product=n\n", + "while ((total>=n) or (product<=(n**2))):\n", + " n = int(input('请输入一个整数,回车结束'))\n", + " total=total+n\n", + " product=product*n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201711680230/3.ipynb b/8-10/201711680230/3.ipynb new file mode 100644 index 00000000..6de5a6e6 --- /dev/null +++ b/8-10/201711680230/3.ipynb @@ -0,0 +1,164 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "##练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式\n", + "noun = input('请输入一个英语名词,回车结束。')\n", + "if noun.endswith('s'): \n", + " t=str('es')\n", + " print(noun+t)\n", + "elif noun.endswith('e'):\n", + " t=str('s')\n", + " print(noun+t)\n", + "elif noun.endswith('o'):\n", + " t=str('es')\n", + " print(noun+t)\n", + "elif noun.endswith('y'): \n", + " print('该名词变为复数时大多把y变i加es')\n", + "elif noun.endswith('fe'): \n", + " print('该名词变为复数时大多把末尾的fe变为v加es')\n", + "else:\n", + " t=str('s')\n", + " print(noun+t)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "##练习 2\n", + "m=int(input('请输入一个不为零的整数m'))\n", + "n=int(input('请输入一个比m小的非零整数'))\n", + "print('如要求从n到m的和请输入a,如要求n到m的积请输入b,如求余数请输入c,如求商请输入d')\n", + "t=str(input('请输入要求'))\n", + "if t==a:\n", + " i=n\n", + " total=0\n", + " while i500):\n", + " total=total+q\n", + " product=product*q\n", + " q=int(input('请输入一个数字'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201711680236/3md.ipynb b/8-10/201711680236/3md.ipynb new file mode 100644 index 00000000..286451a8 --- /dev/null +++ b/8-10/201711680236/3md.ipynb @@ -0,0 +1,112 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个较小的整数3\n", + "请输入一个较大的整数且不等于099\n", + "如果要求和则输入1,如果要求积则输入2,如果要求m/n的余数则输入3,如果要求m整除n的数则输入m/n1\n", + "4947\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图\n", + "#如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "\n", + "m=int(input('请输入一个较小的整数'))\n", + "n=int(input('请输入一个较大的整数且不等于0'))\n", + "\n", + "choice=int(input('如果要求和则输入1,如果要求积则输入2,如果要求m/n的余数则输入3,如果要求m整除n的数则输入m/n'))\n", + "\n", + "if choice==1:\n", + " i=m\n", + " total=m\n", + " while inum2**2):\n", + " break\n", + " \n", + "print('sum=',sum)\n", + "print('product=',product)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201711690064/3.ipynb b/8-10/201711690064/3.ipynb new file mode 100644 index 00000000..2e85f6a6 --- /dev/null +++ b/8-10/201711690064/3.ipynb @@ -0,0 +1,90 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数3\n", + "请输入一个正整数,且不能为0 8\n", + "输入1为求和,2为求积,3为求余,4为求整除2\n", + "24\n" + ] + } + ], + "source": [ + "#练习二\n", + "m=int(input('请输入一个正整数'))\n", + "n=int(input('请输入一个正整数,且不能为0 '))\n", + "\n", + "s=int(input('输入1为求和,2为求积,3为求余,4为求整除'))\n", + "if s==1:\n", + " print(m+n)\n", + "elif s==2:\n", + " print(m*n)\n", + "elif s==3:\n", + " print(m%n)\n", + "else:\n", + " print(m/n)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入字符串:note\n", + "notes\n" + ] + } + ], + "source": [ + "#练习四\n", + "hey_string=input('请输入字符串:')\n", + "if hey_string.endswith('e'):\n", + " print(hey_string+'s')\n", + "elif hey_string.endswith('o') or hey_string.endswith('s') or hey_string.endswith('x') or hey_string.endswith('ch') or hey_string.endswith('sh'):\n", + " print(hey_string+'es')\n", + "\n", + "else:\n", + " print(hey_string+'s')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198201/2.ipynb b/8-10/201721198201/2.ipynb new file mode 100644 index 00000000..7b3f7ef1 --- /dev/null +++ b/8-10/201721198201/2.ipynb @@ -0,0 +1,66 @@ + +# coding: utf-8 + +# In[6]: + +#练习4:用户可以输入的任意多个数字,直到: 输入所有数字的和比当前输入数字小,且输入所有数字的积大于500。 +ji=1 +he=0 +while True: + num=int(input("输入:")) + he=he+num + ji=ji*num + if he500: + break +print("end") + + +# In[ ]: + + + + +# In[3]: + +#练习2:写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。 +i=1 +s=0 +while i<=3: + n=int(input("请输入一个整数,以回车结束")) + s=s+n + i=i+1 + print(s) + + +# In[4]: + +#练习3:用户可以输入的任意多个数字,直到用户不想输入为止。 +print("连续输入数字,直到输入quit时退出") +while True: + num=input("输入:") + if num=="quit": + break +print("end") + + +# In[5]: + +#练习1:仿照任务2完整代码,打印n!。 +n = int(input("请输入一个正整数,以回车结束")) +i = 0 +total = 0 +while i < n: + i = i + 1 + total = total + i +print(n) + + +# In[ ]: + + + + +# In[ ]: + + + diff --git a/8-10/201721198201/3.ipynb b/8-10/201721198201/3.ipynb new file mode 100644 index 00000000..7c529502 --- /dev/null +++ b/8-10/201721198201/3.ipynb @@ -0,0 +1,60 @@ + +# coding: utf-8 + +# In[1]: + +#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。 +s=input("请输入一个运算符号,回车结束") +n=int(input("请输入一个整数,回车结束")) +m=int(input("请输入一个整数,回车结束")) +if s=="+": + print(m+n) +elif s=="*": + print(m*n) +else: + print(m%n) + + +# In[2]: + +#练习四 英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式 +str=input("请输入一个英文名词单数") +if str.endswith("y"): + ss=str[:-1] + print(ss+"ies") +elif str.endswith("f"): + ss=str[:-1] + print(ss+"ves") +elif str.endswith("fe"): + ss=str[:-2] + print(ss+"ves") +elif str.endswith("o"): + print(str+"es") +elif str.endswith("s" or "x" or "ch"or"sh"): + print(str+"es") +else : + print(str+"s") + + +# In[3]: + +# 练习四 给出单数转复数形式 +str=input("请输入一个英文名词复数") +if str.endswith("ves"): + ss=str[:-3] + print(ss+"f") +elif str.endswith("oes" or "ses" or "xes" or "ches" or "shes"): + ss=str[:-2] + print(ss) +elif str.endswith("ies"): + ss=str[:-3] + print(ss+"y") +else: + ss=str[:-1] + print(ss) + + +# In[ ]: + + + diff --git a/8-10/201721198327/2.ipynb b/8-10/201721198327/2.ipynb new file mode 100644 index 00000000..ea37610e --- /dev/null +++ b/8-10/201721198327/2.ipynb @@ -0,0 +1,152 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。5\n", + "120\n" + ] + } + ], + "source": [ + "#练习1:仿照任务2完整代码,打印n!。\n", + "\n", + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "i = 0\n", + "total = 1\n", + "\n", + "while i < n:\n", + " i = i + 1\n", + " total = total * i\n", + " \n", + "print(total)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束,代表输入的数字个数。5\n", + "请输入一个正整数,以回车结束。1\n", + "请输入一个正整数,以回车结束。3\n", + "请输入一个正整数,以回车结束。5\n", + "请输入一个正整数,以回车结束。7\n", + "请输入一个正整数,以回车结束。9\n", + "您输入的5个数字的和是25\n" + ] + } + ], + "source": [ + "#练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。\n", + "\n", + "n = int(input('请输入一个正整数,以回车结束,代表输入的数字个数。'))\n", + "total = 0\n", + "i = 0\n", + "\n", + "while i < n:\n", + " m = int(input('请输入一个正整数,以回车结束。'))\n", + " i = i + 1\n", + " total = total + m\n", + "\n", + "print('您输入的',n,'个数字的和是',total,sep = '')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入任意个数字,不想输入时请输入q终止。5\n", + "请输入任意个数字,不想输入时请输入q终止。74\n", + "请输入任意个数字,不想输入时请输入q终止。4654\n", + "请输入任意个数字,不想输入时请输入q终止。87987\n", + "请输入任意个数字,不想输入时请输入q终止。4654\n", + "请输入任意个数字,不想输入时请输入q终止。65\n", + "请输入任意个数字,不想输入时请输入q终止。q\n" + ] + } + ], + "source": [ + "#练习3:用户可以输入的任意多个数字,直到用户不想输入为止。\n", + "\n", + "n = input('请输入任意个数字,不想输入时请输入q终止。')\n", + "\n", + "while n != 'q':\n", + " n = input('请输入任意个数字,不想输入时请输入q终止。')" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束:2\n", + "请输入一个正整数,以回车结束:3\n", + "请输入一个正整数,以回车结束:5\n", + "请输入一个正整数,以回车结束:11\n", + "请输入一个正整数,以回车结束:22\n", + "请输入一个正整数,以回车结束:44\n", + "这几个数字的和为43,积为7260\n" + ] + } + ], + "source": [ + "#练习4:用户可以输入的任意多个数字,直到输入所有数字的和比当前输入数字小,且输入所有数字的积比当前输入数字的平方大。\n", + "\n", + "num1 = int(input('请输入一个正整数,以回车结束:'))\n", + "num2 = int(input('请输入一个正整数,以回车结束:'))\n", + "total = num1 + num2\n", + "product = num1 * num2\n", + "n = int(input('请输入一个正整数,以回车结束:'))\n", + "\n", + "while ((total>=n) or (product<=(n**2))):\n", + " total = total + n\n", + " product = product * n\n", + " n = int(input('请输入一个正整数,以回车结束:'))\n", + "\n", + "print('这几个数字的和为',total,',积为',product,sep ='')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198327/3.ipynb b/8-10/201721198327/3.ipynb new file mode 100644 index 00000000..faab4c03 --- /dev/null +++ b/8-10/201721198327/3.ipynb @@ -0,0 +1,131 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个不为零的整数,以回车结束:-3\n", + "请输入一个不为零的整数,以回车结束:4\n", + "如果要求这两个数的和请输入\"求和\";如果要求这两个数的积请输入\"求积\";如果要求第一个数除以第二个数的余数请输入\"求余\";否则计算第一个数整除第二个数的值\n", + "求积\n", + "积为0\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "\n", + "m = int(input('请输入一个不为零的整数,以回车结束:'))\n", + "n = int(input('请输入一个不为零的整数,以回车结束:'))\n", + "\n", + "print('如果要求这两个数的和请输入\"求和\";如果要求这两个数的积请输入\"求积\";如果要求第一个数除以第二个数的余数请输入\"求余\";否则计算第一个数整除第二个数的值')\n", + "\n", + "x = input() \n", + "\n", + "if x == \"求和\":\n", + " if m == n:\n", + " print('和为',m + n,sep ='')\n", + " elif m > n:\n", + " total = 0\n", + " while n <= m:\n", + " total = total + n\n", + " n = n + 1\n", + " print('和为',total,sep ='')\n", + " else:\n", + " total = 0\n", + " while m <= n:\n", + " total = total + m\n", + " m = m + 1\n", + " print('和为',total,sep ='')\n", + " \n", + "elif x == \"求积\":\n", + " if m == n:\n", + " print('积为',m * n,sep ='')\n", + " elif m > n:\n", + " total = 1\n", + " while n <= m:\n", + " total = total * n\n", + " n = n + 1\n", + " print('积为',total,sep ='')\n", + " else:\n", + " total = 1\n", + " while m <= n:\n", + " total = total * m\n", + " m = m + 1\n", + " print('积为',total,sep ='')\n", + " \n", + "elif x == \"求余\":\n", + " print('余数为',m % n,sep ='')\n", + " \n", + "else:\n", + " print('整除值为', m // n,sep ='')" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个英语名词,回车结束。leaf\n", + "该名词变为复数时大多把末尾的f变为v加es\n" + ] + } + ], + "source": [ + "#练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。\n", + "\n", + "noun = input('请输入一个英语名词,回车结束。')\n", + "if noun.endswith('s'): \n", + " print('该名词变为复数时直接在末尾加es')\n", + "elif noun.endswith('x'): \n", + " print('该名词变为复数时直接在末尾加es')\n", + "elif noun.endswith('z'): \n", + " print('该名词变为复数时直接在末尾加es')\n", + "elif noun.endswith('sh'): \n", + " print('该名词变为复数时直接在末尾加es')\n", + "elif noun.endswith('ch'): \n", + " print('该名词变为复数时直接在末尾加es')\n", + "elif noun.endswith('y'): \n", + " print('该名词变为复数时大多把y变i加es')\n", + "elif noun.endswith('o'): \n", + " print('该名词变为复数时大多直接在末尾加es')\n", + "elif noun.endswith('f'): \n", + " print('该名词变为复数时大多把末尾的f变为v加es')\n", + "elif noun.endswith('fe'): \n", + " print('该名词变为复数时大多把末尾的fe变为v加es')\n", + "else:\n", + " print('该名词变为复数时直接加s')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198328/2.ipynb b/8-10/201721198328/2.ipynb new file mode 100644 index 00000000..220969f6 --- /dev/null +++ b/8-10/201721198328/2.ipynb @@ -0,0 +1,142 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数5\n", + "n!的值为: 120\n" + ] + } + ], + "source": [ + "#仿照任务2完整代码,打印n!\n", + "n=int(input('请输入一个正整数'))\n", + "product=1\n", + "for i in range(1,n+1):\n", + " product=product*i\n", + "print('n!的值为:',product) \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入整数个数5\n", + "请输入整数3\n", + "请输入整数5\n", + "请输入整数6\n", + "请输入整数7\n", + "请输入整数3\n", + "输入的整数和为: 24\n" + ] + } + ], + "source": [ + "#练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码\n", + "n=int(input('请输入整数个数'))\n", + "sum=0\n", + "i=0\n", + "while itotal:\n", + " if mult>500:\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198329/3.ipynb b/8-10/201721198329/3.ipynb new file mode 100644 index 00000000..5b4cc741 --- /dev/null +++ b/8-10/201721198329/3.ipynb @@ -0,0 +1,210 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入一个数2\n", + "再输入一个数4\n", + "求和输入1,求积输入2,求余输入3,整除输入42\n", + "24\n" + ] + } + ], + "source": [ + "#练习二\n", + "total=0\n", + "mult=1\n", + "m=int(input('输入一个数'))\n", + "n=int(input('再输入一个数'))\n", + "k=int(input('求和输入1,求积输入2,求余输入3,整除输入4'))\n", + "\n", + "if k==1:\n", + " if m>n:\n", + " min=n\n", + " max=m\n", + " else:\n", + " min=m\n", + " max=n\n", + " while min<=max:\n", + " total=total+min\n", + " min=min+1\n", + " print(total)\n", + "\n", + "elif k==2:\n", + " if m>n:\n", + " min=n\n", + " max=m\n", + " else:\n", + " min=m\n", + " max=n\n", + " while min<=max:\n", + " mult=mult*min\n", + " min=min+1\n", + " print(mult)\n", + "\n", + "elif k==3:\n", + " print(m%n)\n", + "\n", + "else:\n", + " print(m//n)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入一个单词apple\n", + "加s\n" + ] + } + ], + "source": [ + "#练习四\n", + "n=str(input('输入一个单词'))\n", + "if n.endswith('o'):\n", + " print('有生命的加es, 无生命的加s')\n", + "elif n.endswith('f'):\n", + " print('变f为v, 再加-es')\n", + "elif n.endswith('fe'): \n", + " print('变f为v, 再加-s')\n", + "elif n.endswith('y'): \n", + " print('变y为i, 再加-es')\n", + "elif n.endswith('s'): \n", + " print('加-es')\n", + "elif n.endswith('sh'): \n", + " print('加-es')\n", + "elif n.endswith('sh'):\n", + " print('加-es')\n", + "elif n.endswith('x'): \n", + " print('加-es')\n", + "elif n.endswith('ch'): \n", + " print('加-es')\n", + "else:\n", + " print('加s')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198578/2.ipynb b/8-10/201721198578/2.ipynb new file mode 100644 index 00000000..a75dc3bc --- /dev/null +++ b/8-10/201721198578/2.ipynb @@ -0,0 +1,194 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。\n", + "6\n", + "720\n" + ] + } + ], + "source": [ + "#练习1:仿照任务2完整代码,打印n!。\n", + "n = int(input('请输入一个正整数,以回车结束。\\n'))\n", + "\n", + "i = 0\n", + "total = 1\n", + "\n", + "while i < n:\n", + " i = i + 1\n", + " total = total * i\n", + " \n", + "print(total)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数的个数,以回车结束。\n", + "3\n", + "请输入一个正整数,以回车结束。\n", + "4\n", + "请输入一个正整数,以回车结束。\n", + "5\n", + "请输入一个正整数,以回车结束。\n", + "6\n", + "15\n" + ] + } + ], + "source": [ + "#练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。\n", + "n = int(input('请输入一个正整数的个数,以回车结束。\\n'))\n", + "i = 0\n", + "total = 0\n", + "\n", + "while i < n:\n", + " m = int(input('请输入一个正整数,以回车结束。\\n'))\n", + " i = i + 1\n", + " total = total + m\n", + " \n", + "print(total)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个数字5\n", + "请输入一个数字80\n", + "请输入一个数字a\n", + "could not convert string to float: 'a'\n" + ] + } + ], + "source": [ + "#练习3:用户可以输入的任意多个数字,直到用户不想输入为止。\n", + "n = 0\n", + "while n != 'q':\n", + " try:\n", + " n = float(input('请输入一个数字\\n'))\n", + " except Exception as e :\n", + " print(e)\n", + " break\n", + " else:\n", + " n = float(input('请输入一个数字\\n'))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个数字,以回车结束。\n", + "-1\n", + "请输入一个数字,以回车结束。\n", + "-2\n", + "请输入一个数字,以回车结束。\n", + "-2\n", + "请输入一个数字,以回车结束。\n", + "-2\n" + ] + } + ], + "source": [ + "#练习4:用户可以输入的任意多个数字,直到输入所有数字的和比当前输入数字小,且输入所有数字的积比当前输入数字的平方大。\n", + "n = 0\n", + "total = 0\n", + "product = 1\n", + "while total >= n or product <= n**2:\n", + " n = int(input('请输入一个数字,以回车结束。\\n'))\n", + " if n == 0:\n", + " n = int(input('请不要输入0。请输入一个数字,以回车结束。\\n'))\n", + " total = total +n\n", + " product = product * n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#练习4:用户可以输入的任意多个数字,直到: 输入所有数字的和比当前输入数字小,且输入所有数字的积大于500。\n", + "n = int(input('请输入一个数字,以回车结束。\\n'))\n", + "if n == 0:\n", + " n = int(input('请不要输入0。请输入一个数字,以回车结束。\\n'))\n", + "total = n\n", + "product = n\n", + "while n :\n", + " n = int(input('请输入一个数字,以回车结束。\\n'))\n", + " if n == 0:\n", + " n = int(input('请不要输入0。请输入一个数字,以回车结束。\\n'))\n", + " if total < n and product > 500 :\n", + " print('end')\n", + " break\n", + " total += n\n", + " product *= n\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198578/3.ipynb b/8-10/201721198578/3.ipynb new file mode 100644 index 00000000..e549f8ff --- /dev/null +++ b/8-10/201721198578/3.ipynb @@ -0,0 +1,167 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个数字,以回车结束。4\n", + "请输入一个数字,以回车结束。3\n", + "请问输入目的,和代表求和,积代表求乘积,余代表求余数,除代表求整除,q代表退出。余\n", + "remainder is: 1 \n", + "\n", + "请输入一个数字,以回车结束。4\n", + "请输入一个数字,以回车结束。3\n", + "请问输入目的,和代表求和,积代表求乘积,余代表求余数,除代表求整除,q代表退出。除\n", + "division is: 1.3333333333333333 \n", + "\n", + "请输入一个数字,以回车结束。6\n", + "请输入一个数字,以回车结束。4\n", + "请问输入目的,和代表求和,积代表求乘积,余代表求余数,除代表求整除,q代表退出。q\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "porpuse = 0\n", + "total = 0\n", + "product = 1\n", + "\n", + "while porpuse != 'q':\n", + " n = int(input('请输入一个数字,以回车结束。'))\n", + " m = int(input('请输入一个数字,以回车结束。'))\n", + " porpuse = input('请问输入目的,和代表求和,积代表求乘积,余代表求余数,除代表求整除,q代表退出。')\n", + " if n > m:\n", + " maxNum = n\n", + " minNum = m\n", + " else:\n", + " maxNum = m\n", + " minNum = n\n", + " \n", + " i = minNum \n", + " if porpuse == '和':\n", + " while i <= maxNum:\n", + " total += i\n", + " i += 1\n", + " print ('total is:',total,'\\n')\n", + " \n", + " elif porpuse == '积':\n", + " while i <= maxNum:\n", + " product *= i\n", + " i += 1\n", + " print ('product is:',product,'\\n')\n", + " elif porpuse == '余':\n", + " remainder = maxNum % minNum\n", + " print ('remainder is:',remainder,'\\n')\n", + " elif porpuse == '除':\n", + " division = maxNum / minNum\n", + " print ('division is:',division,'\\n')\n", + " elif porpuse == 'q':\n", + " break\n", + " else:\n", + " porpuse = input('请不要输入无关要求\\n,请问输入目的,和代表求和,积代表求乘积,余代表求余数,除代表求整除,q代表退出。')" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "please input a verb:\n", + " fly\n", + "flies\n", + "please input a verb:\n", + " see\n", + "sees\n", + "please input a verb:\n", + " chef\n", + "cheves\n", + "please input a verb:\n", + " q\n" + ] + } + ], + "source": [ + "#练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。\n", + "#1.一般动词+S一个:like→likes\n", + "#2.S,X,ch,sh结尾的加es(随便一个):kiss→kisses;fix→fixes;watch→watches;wash→washes;\n", + "#3.O辅音+O es和o元音+o s。:go→goes;\n", + "#4.y 辅音+y去y+ies和元音+y+s。: worry→worries; buy→buys;\n", + "#5.结尾是f和fe的去f和fe加ves。:stuff→stuves;\n", + "\n", + "#verb = 'fly'\n", + "#print(verb[:-1] + 'ies')\n", + "verb = 0\n", + "while verb != 'q' :\n", + " verb = input('please input a verb:\\n ')\n", + " \n", + " if verb.endswith('s') or verb.endswith('x') or verb.endswith('sh') or verb.endswith('s=ch'):\n", + " verb = verb + 'es'\n", + " print (verb)\n", + " \n", + " elif verb.endswith('o'): \n", + " if verb.endswith('ao') or verb.endswith('eo') or verb.endswith('io') or verb.endswith('oo') or verb.endswith('uo'):\n", + " verb = verb + 's'\n", + " else:\n", + " verb = verb + 'es'\n", + " print (verb)\n", + " \n", + " elif verb.endswith('y'):\n", + " if verb.endswith('ay') or verb.endswith('ey') or verb.endswith('iy') or verb.endswith('oy') or verb.endswith('uy'):\n", + " verb = verb + 's'\n", + " else:\n", + " verb = verb[:-1] + 'ies'\n", + " print (verb)\n", + " elif verb.endswith('f'):\n", + " verb = verb[:-1] + 'ves'\n", + " print (verb)\n", + " elif verb.endswith('fe'):\n", + " verb = verb[:-2] + 'ves'\n", + " print (verb)\n", + " elif verb == 'q' :\n", + " break\n", + " else:\n", + " verb = verb + 's'\n", + " print (verb) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198579/2.ipynb b/8-10/201721198579/2.ipynb new file mode 100644 index 00000000..2aa82917 --- /dev/null +++ b/8-10/201721198579/2.ipynb @@ -0,0 +1,148 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入一个整数5\n", + "120\n" + ] + } + ], + "source": [ + "#练习1:仿照任务2完整代码,打印n!。\n", + "n=int(input('输入一个整数'))\n", + "total=1\n", + "i=0\n", + "while i500:\n", + " break\n", + " mul=mul*i\n", + " sum=sum+i\n", + "print('满足条件')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198579/3.ipynb b/8-10/201721198579/3.ipynb new file mode 100644 index 00000000..72935081 --- /dev/null +++ b/8-10/201721198579/3.ipynb @@ -0,0 +1,138 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入计算式以#结束\n", + "输入计算符*\n", + "输入第一个整数5\n", + "输入第二个整数5\n", + "25\n", + "输入计算符#\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输('输入计算式以#结束')\n", + "print('输入计算式以#结束')\n", + "p=input('输入计算符')\n", + "while p!='#':\n", + " m=int(input('输入第一个整数'))\n", + " n=int(input('输入第二个整数'))\n", + " if p=='+':\n", + " print(m+n)\n", + " elif p=='*':\n", + " print(m*n)\n", + " elif p=='%':\n", + " print(m%n)\n", + " else:\n", + " print(m/n)\n", + " p=input('输入计算符')" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入单词fly\n", + "flies\n", + "输入单词#\n" + ] + } + ], + "source": [ + " #练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。\n", + "char=input('输入单词')\n", + "while char!='#':\n", + " if char.endswith('s') or char.endswith('x') or char.endswith('z') or char.endswith('ch') or char.endswith('sh') or char.endswith('o'):\n", + " print(char+'es')\n", + " elif char.endswith('f') or char.endswith('fe'):\n", + " if char.endswith('fe'):\n", + " char=char[:-2]\n", + " if char.endswith('f'):\n", + " char=char[:-1]\n", + " print(char+'ves')\n", + " elif char.endswith('y'):\n", + " if char.endswith('ay') or char.endswith('ey') or char.endswith('iy') or char.endswith('oy') or char.endswith('uy') :\n", + " print(char+'s')\n", + " else:\n", + " char=char[:-1]\n", + " print(char+'ies')\n", + " elif char.endswith('us'):\n", + " char=char[:-2]\n", + " print(char+'i')\n", + " else :\n", + " print(char+'s')\n", + " char=input('输入单词')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198580/2.ipynb b/8-10/201721198580/2.ipynb new file mode 100644 index 00000000..59ba56b6 --- /dev/null +++ b/8-10/201721198580/2.ipynb @@ -0,0 +1,731 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习1:键入如下代码并观察执行结果" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的名字,以回车结束。Mike\n", + "你好 Mike\n", + "请输入一个正整数,以回车结束。50\n", + "请输入一个正整数,以回车结束。30\n", + "两个数的和是: 80\n", + "再见, Mike\n" + ] + } + ], + "source": [ + "name = input('请输入你的名字,以回车结束。')\n", + "print('你好', name)\n", + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "m = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "print('两个数的和是:', m + n)\n", + "print('再见,', name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的名字,以回车结束。Mike\n", + "你好 Mike\n", + "请输入一个正整数,以数字0作为结束。23\n", + "请输入一个正整数,以数字0作为结束。12\n", + "请输入一个正整数,以数字0作为结束。67\n", + "请输入一个正整数,以数字0作为结束。88\n", + "请输入一个正整数,以数字0作为结束。34\n", + "请输入一个正整数,以数字0作为结束。22\n", + "请输入一个正整数,以数字0作为结束。0\n", + "所有整数的和是: 246\n", + "再见 Mike\n" + ] + } + ], + "source": [ + "name = input('请输入你的名字,以回车结束。')\n", + "print('你好', name)\n", + "total = 0\n", + "while(1):\n", + " m = int(input('请输入一个正整数,以数字0作为结束。'))\n", + " total = total + m\n", + " if (m == 0):\n", + " break\n", + "print('所有整数的和是:', total)\n", + "print('再见', name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习3:用户可以输入的任意多个数字,直到用户不想输入为止。" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个数字,以q结束。23\n", + "请输入一个数字,以q结束。12\n", + "请输入一个数字,以q结束。33\n", + "请输入一个数字,以q结束。63\n", + "请输入一个数字,以q结束。21\n", + "请输入一个数字,以q结束。15\n", + "请输入一个数字,以q结束。q\n" + ] + } + ], + "source": [ + "while(1):\n", + " m = input('请输入一个数字,以q结束。')\n", + " if (m == 'q'):\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习4:用户可以输入的任意多个数字,直到输入所有数字的和比当前输入数字小,且输入所有数字的积比当前输入数字的平方大。" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的名字,以回车结束。Mike\n", + "你好 Mike\n", + "请输入一个正整数,以回车结束。10\n", + "请输入一个正整数,以回车结束。12\n", + "请输入一个正整数,以回车结束。14\n", + "请输入一个正整数,以回车结束。38\n", + "所有整数的和是: 36\n", + "再见 Mike\n" + ] + } + ], + "source": [ + "name = input('请输入你的名字,以回车结束。')\n", + "print('你好', name)\n", + "total = 0\n", + "accu = 1\n", + "while(1):\n", + " m = int(input('请输入一个正整数,以回车结束。'))\n", + " if(total < m and accu > m * m):\n", + " break\n", + " total = total + m\n", + " accu = accu * m\n", + "print('所有整数的和是:', total)\n", + "print('再见', name)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100\n" + ] + } + ], + "source": [ + "print(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.23\n", + "-100.23\n", + "Hello, world.\n", + "你好,python!\n", + "-100.23\n" + ] + } + ], + "source": [ + "print(1.23)\n", + "print(-100.23)\n", + "print('Hello, world.')\n", + "print('你好,python!')\n", + "print('-100.23')" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I am OK.\n" + ] + } + ], + "source": [ + "print('I am OK.')" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "45\n" + ] + } + ], + "source": [ + "print(1 + 2)\n", + "print(5 + 6 + 7 + 8 + 9 + 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "25.136\n", + "520.9020387866733\n" + ] + } + ], + "source": [ + "print(8 - 100 + 20 * 5)\n", + "print(3.142 * 8)\n", + "print((973 * 863 + 985 * 211) / 2011)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], + "source": [ + "print(1 + 2 + 3 + 4)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15\n", + "2.8\n" + ] + } + ], + "source": [ + "n = 2\n", + "n = 5\n", + "m = 7.2\n", + "print(1 + 2 + 3 + 4 + n)\n", + "print(1 + 2 + 3 + 4 - m)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "3\n", + "6\n" + ] + } + ], + "source": [ + "n = 0\n", + "n = n + 1\n", + "print(n)\n", + "n = n + 2\n", + "print(n)\n", + "n = n + 3\n", + "print(n)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n" + ] + } + ], + "source": [ + "n = 7\n", + "i = 0\n", + "while i < n:\n", + " i = i + 1\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "False\n", + "False\n" + ] + } + ], + "source": [ + "print(10 > 5)\n", + "print(10 < 1.1)\n", + "flag = False\n", + "print(flag)\n", + "print('int' < 'example')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5050\n" + ] + } + ], + "source": [ + "n = 100\n", + "i = 0\n", + "total = 0\n", + "while i < n:\n", + " i = i + 1\n", + " total = total + i\n", + "print(total)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 hello\n", + "100 hello\n" + ] + } + ], + "source": [ + "n = input()\n", + "print(n)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n", + "150\n" + ] + } + ], + "source": [ + "n = int(input())\n", + "print(n + 100)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100\n", + "200\n" + ] + } + ], + "source": [ + "n = input()\n", + "n = int(n)\n", + "print(n + 100)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "1.5\n", + "81\n", + "2.5\n", + "125\n", + "2\n", + "1\n" + ] + } + ], + "source": [ + "print(4 + 6)\n", + "print(3.5 - 2)\n", + "print(9 * 9)\n", + "print(5 / 2)\n", + "print(5 ** 3)\n", + "print(5//2)\n", + "print(7 % 3)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "1\n", + "-1\n", + "-1\n", + "100\n", + "100\n", + "1.0\n", + "1.0\n", + "1\n", + "3\n", + "3\n", + "1000\n", + "1000\n" + ] + } + ], + "source": [ + "i = 0\n", + "i = i + 1\n", + "print(i)\n", + "i = 0\n", + "i +=1\n", + "print(i)\n", + "i = 0\n", + "i = i - 1\n", + "print(i)\n", + "i = 0\n", + "i -= 1\n", + "print(i)\n", + "i = 10\n", + "i = i * 10\n", + "print(i)\n", + "i = 10\n", + "i *= 10\n", + "print(i)\n", + "i = 10\n", + "i = i / 10\n", + "print(i)\n", + "i = 10\n", + "i /= 10\n", + "print(i)\n", + "i = 10\n", + "i %= 3\n", + "print(i)\n", + "i = 10\n", + "i = i // 3\n", + "print(i)\n", + "i = 10\n", + "i //= 3\n", + "print(i)\n", + "i = 10\n", + "i = i ** 3\n", + "print(i)\n", + "i = 10\n", + "i **= 3\n", + "print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1000\n", + "1000\n" + ] + } + ], + "source": [ + "'''\n", + "这是一段注释\n", + "作为多行注释的示例\n", + "也是含有空行程序的示例\n", + "'''\n", + "i = 10\n", + "i = i ** 3 \n", + "print(i)\n", + "\n", + "i = 10\n", + "i **= 3 \n", + "print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "print(10 == 10)\n", + "print(10 != 10)\n", + "print(10 > 5.1)\n", + "print(10.2 < 5)\n", + "print(5 >= 10)\n", + "print(5 <= 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "print('apple' > 'banana')\n", + "print('red' == 'red')\n", + "print('red' == 10)\n", + "print('red' != 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "False\n", + "True\n", + "True\n", + "False\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "a = True\n", + "b = False\n", + "print(a and b)\n", + "print(a and True)\n", + "print(False and b)\n", + "print(a or b)\n", + "print(b or True)\n", + "print(not a)\n", + "print(not b)\n", + "print(not a and b)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数,按回车结束。240\n", + "240\n" + ] + } + ], + "source": [ + "n = input('请输入一个整数,按回车结束。')\n", + "print(n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2.7 完整代码" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。10\n", + "55\n" + ] + } + ], + "source": [ + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "i = 0\n", + "total = 0\n", + "while i < n:\n", + " i = i + 1\n", + " total = total + i\n", + "print(total)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198580/3.ipynb b/8-10/201721198580/3.ipynb new file mode 100644 index 00000000..2cdacf32 --- /dev/null +++ b/8-10/201721198580/3.ipynb @@ -0,0 +1,581 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个较小的整数:3\n", + "请输入一个较大的整数:6\n", + "用户意图:求积\n", + "m *...* n = 360\n" + ] + } + ], + "source": [ + "m = int(input('请输入一个较小的整数:'))\n", + "n = int(input('请输入一个较大的整数:'))\n", + "q = input('用户意图:')\n", + "if (q == '求和'):\n", + " print('(m + n) / 2 * (n - m + 1) = ', (m + n) / 2 * (n - m + 1) )\n", + "elif (q == '求积'):\n", + " product = m\n", + " while m < n:\n", + " m = m + 1\n", + " product = product * m\n", + " print('m *...* n = ', product) \n", + "elif (q == '求余'):\n", + " print('m % n = ', m % n) \n", + "else :\n", + " print('m // n = ', m // n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习 4:英文单词单数转复数,要求输入一个英文名词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入的英文名词(单数形式)是:house\n", + "houses\n" + ] + } + ], + "source": [ + "Word = input('输入的英文名词(单数形式)是:')\n", + "if (Word.endswith('s') or Word.endswith('x') or Word.endswith('ch') or Word.endswith('sh')):\n", + " Word = Word + 'es'\n", + " print(Word)\n", + "elif (Word[-2] == 'a' and Word[-1] == 'y'):\n", + " Word = Word[:-1] +'ies'\n", + " print(Word)\n", + "elif (Word[-2] == 'e' and Word[-1] == 'y'):\n", + " Word = Word[:-1] +'ies'\n", + " print(Word)\n", + "elif (Word[-2] == 'i' and Word[-1] == 'y'):\n", + " Word = Word[:-1] +'ies'\n", + " print(Word)\n", + "elif (Word[-2] == 'o' and Word[-1] == 'y'):\n", + " Word = Word[:-1] +'ies'\n", + " print(Word)\n", + "elif (Word[-2] == 'u' and Word[-1] == 'y'):\n", + " Word = Word[:-1] +'ies'\n", + " print(Word)\n", + "elif (Word[-1] == 'f'):\n", + " Word = Word[:-1] + 'ves'\n", + "elif (Word[-2:] == 'fe'):\n", + " Word = Word[:-2] + 'ves'\n", + "elif(Word[-1] == 'o'):\n", + " if('有生命'):\n", + " print('在单词后面加es')\n", + " else:\n", + " print('在单词后面加s')\n", + "else:\n", + " Word = Word + 's'\n", + " print(Word) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习 1:写程序,可由键盘读入用户姓名例如Mr. right,让用户输入出生的月份与日期,判断用户星座,假设用户是金牛座,则输出,Mr. right,你是非常有性格的金牛座!。" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please input your name:Wendy\n", + "The month of birth:4\n", + "The day of birth:28\n", + "Wendy ,你是一个稳健固执的金牛座!\n" + ] + } + ], + "source": [ + "name = input('Please input your name:')\n", + "m = int(input('The month of birth:'))\n", + "d = int(input('The day of birth:'))\n", + "\n", + "if (m == 1):\n", + " if (d >= 1 and d < 20):\n", + " print(name,',你是一个执着现实的摩羯座!')\n", + " elif(d >= 20 and d <= 31):\n", + " print(name,',你是一个自由博爱的水瓶座!')\n", + "elif(m == 2):\n", + " if (d >= 1 and d <= 18):\n", + " print(name,',你是一个自由博爱的水瓶座!')\n", + " elif(d > 18 and d <= 30):\n", + " print(name,',你是一个浪漫梦幻的双鱼座!')\n", + "elif(m == 3):\n", + " if (d >= 1 and d <= 20):\n", + " print(name,',你是一个浪漫梦幻的双鱼座!')\n", + " elif(d > 20 and d <= 31):\n", + " print(name,',你是一个热情活力的白羊座!')\n", + "elif(m == 4):\n", + " if (d >= 1 and d <= 19):\n", + " print(name,',你是一个热情活力的白羊座!')\n", + " elif(d > 19 and d < 31):\n", + " print(name,',你是一个稳健固执的金牛座!')\n", + "elif(m == 5):\n", + " if (d >= 1 and d <= 20):\n", + " print(name,',你是一个热情活力的金牛座!')\n", + " elif(d > 20 and d <= 31):\n", + " print(name,',你是一个花心多变的双子座!')\n", + "elif(m == 6):\n", + " if (d >= 1 and d <= 21):\n", + " print(name,',你是一个花心多变的双子座!')\n", + " elif(d > 21 and d < 31):\n", + " print(name,',你是一个敏感柔情的巨蟹座!')\n", + "elif(m == 7):\n", + " if (d >= 1 and d <= 22):\n", + " print(name,',你是一个敏感柔情的巨蟹座!')\n", + " elif(d > 22 and d <= 31):\n", + " print(name,',你是一个骄傲威严的狮子座!')\n", + "elif(m == 8):\n", + " if (d >= 1 and d <= 22):\n", + " print(name,',你是一个骄傲威严的狮子座!')\n", + " elif(d > 22 and d <= 31):\n", + " print(name,',你是一个完美理性的处女座!')\n", + "elif(m == 9):\n", + " if (d >= 1 and d <= 22):\n", + " print(name,',你是一个完美理性的处女座!')\n", + " elif(d > 22 and d < 31):\n", + " print(name,',你是一个公平和谐的天秤座!')\n", + "elif(m == 10):\n", + " if (d >= 1 and d <= 23):\n", + " print(name,',你是一个公平和谐的天秤座!')\n", + " elif(d > 23 and d <= 31):\n", + " print(name,',你是一个神秘敏锐的天蝎座!')\n", + "elif(m == 11):\n", + " if (d >= 1 and d <= 22):\n", + " print(name,',你是一个神秘敏锐的天蝎座!')\n", + " elif(d > 22 and d < 31):\n", + " print(name,',你是一个自由乐观的射手座!')\n", + "elif(m == 12):\n", + " if (d >= 1 and d <= 21):\n", + " print(name,',你是一个自由乐观的射手座!')\n", + " elif(d > 21 and d <= 31):\n", + " print(name,',你是一个执着现实的摩羯座!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "练习 3:写程序,能够根据北京雾霾PM2.5数值给出对应的防护建议。如当PM2.5数值大于500,则应该打开空气净化器,戴防雾霾口罩等。" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入北京的雾霾指数:50\n", + "适合户外运动\n" + ] + } + ], + "source": [ + "PM = float(input('请输入北京的雾霾指数:'))\n", + "if (PM > 500):\n", + " print('应该打开空气净化器')\n", + "elif(PM > 100):\n", + " print('应该带雾霾口罩')\n", + "elif(PM > 0):\n", + " print('适合户外运动')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "尝试性练习:写程序,能够在屏幕上显示空行。" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Nice to meet you.\n", + "\n", + "\n", + "Nice to meet you too!\n" + ] + } + ], + "source": [ + "print('Nice to meet you.')\n", + "print('\\n')\n", + "print('Nice to meet you too!')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "挑战性练习:写程序,由用户输入一些整数,能够得到几个整数中的次大值(第二大的值)并输出。" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入整数的个数:5\n", + "请输入一个整数:12\n", + "请输入一个整数:33\n", + "请输入一个整数:15\n", + "请输入一个整数:38\n", + "请输入一个整数:11\n", + "33\n" + ] + } + ], + "source": [ + "j = int(input('请输入整数的个数:'))\n", + "max_num = int(input('请输入一个整数:'))\n", + "secondmax_num = max_num\n", + "i = 1\n", + "while i < j:\n", + " i = i + 1\n", + " m = int(input('请输入一个整数:'))\n", + " if (m > max_num):\n", + " secondmax_num = max_num\n", + " max_num = m\n", + " elif (m > secondmax_num):\n", + " secondmax_num = m\n", + " else:\n", + " pass\n", + "print(secondmax_num)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入第一个数,回车结束32\n", + "请输入第二个数,回车结束12\n", + "将小的数字乘以2: 24\n" + ] + } + ], + "source": [ + "m = int(input('请输入第一个数,回车结束'))\n", + "n = int(input('请输入第二个数,回车结束'))\n", + "if m > n:\n", + " n *= 2\n", + " print('将小的数字乘以2:', n)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入第一个数,回车结束5\n", + "请输入第二个数,回车结束6\n", + "5 <= 6\n", + "请输入第一个数,回车结束6\n", + "请输入第二个数,回车结束5\n", + "6 > 5\n" + ] + } + ], + "source": [ + "m = int(input('请输入第一个数,回车结束'))\n", + "n = int(input('请输入第二个数,回车结束'))\n", + "if m > n:\n", + " print(m, '>', n)\n", + "else:\n", + " print(m, '<=', n)\n", + "m = int(input('请输入第一个数,回车结束'))\n", + "n = int(input('请输入第二个数,回车结束'))\n", + "if m > n:\n", + " print(m, '>', n)\n", + "else:\n", + " print(m, '<=', n)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入第一个数,回车结束3\n", + "请输入第二个数,回车结束6\n", + "3 < 6\n" + ] + } + ], + "source": [ + "m = int(input('请输入第一个数,回车结束'))\n", + "n = int(input('请输入第二个数,回车结束'))\n", + "if m > n:\n", + " print(m, '>', n)\n", + "elif m < n:\n", + " print(m, '<', n)\n", + "else:\n", + " print(m, '=', n)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个数,回车结束39\n", + "39 > 0\n" + ] + } + ], + "source": [ + "m = int(input('请输入一个数,回车结束'))\n", + "if m > 1000:\n", + " print(m, '>', 1000)\n", + "elif m > 500:\n", + " print(m, '>', 500)\n", + "elif m > 100:\n", + " print(m, '>', 100)\n", + "elif m > 0:\n", + " print(m, '>', 0)\n", + "else:\n", + " print(m, '<=', 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数,回车结束20\n", + "请输入一个整数,回车结束2\n", + "请输入一个整数,回车结束3\n", + "请输入一个整数,回车结束6\n", + "请输入一个整数,回车结束45\n", + "请输入一个整数,回车结束32\n", + "请输入一个整数,回车结束33\n", + "请输入一个整数,回车结束24\n", + "请输入一个整数,回车结束16\n", + "请输入一个整数,回车结束7\n", + "请输入一个整数,回车结束87\n", + "最大值是: 87\n" + ] + } + ], + "source": [ + "max_number = int(input('请输入一个整数,回车结束'))\n", + "\n", + "i = 0\n", + "while i < 10:\n", + " i += 1\n", + " n = int(input('请输入一个整数,回车结束'))\n", + " if n > max_number:\n", + " max_number = n\n", + "\n", + "print('最大值是:', max_number)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "多个参数 5 69 1.0\n", + "多个参数 5 69 1.0\n", + "多个参数,5,69,1.0\n", + "多个参数 5 69 1.0\n", + "多个参数 ,5 ,69 ,1.0\n", + "多个参数5691.0\n" + ] + } + ], + "source": [ + "print('多个参数', 5, 4078%211, 407.8//211)\n", + "print('多个参数', 5, 4078%211, 407.8//211, sep = ' ')\n", + "print('多个参数', 5, 4078%211, 407.8//211, sep = ',')\n", + "print('多个参数', 5, 4078%211, 407.8//211, sep = ' ')\n", + "print('多个参数', 5, 4078%211, 407.8//211, sep = ' ,')\n", + "print('多个参数', 5, 4078%211, 407.8//211, sep = '')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.由用户输入几个整数,打印最大值,最小值、平均值。" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数,回车结束。5\n", + "请输入一个整数,回车结束。7\n", + "请输入一个整数,回车结束。9\n", + "请输入一个整数,回车结束。1\n", + "请输入一个整数,回车结束。3\n", + "请输入一个整数,回车结束。0\n", + "请输入一个整数,回车结束。0\n", + "最大值是: 9\n", + "最小值是: 0\n", + "平均值是: 2.857142857142857\n" + ] + } + ], + "source": [ + "max_num = int(input('请输入一个整数,回车结束。'))\n", + "min_num = max_num\n", + "n = 1\n", + "total = 0\n", + "while(1):\n", + " m =int(input('请输入一个整数,回车结束。'))\n", + " total = total + m\n", + " n = n + 1\n", + " ave = total / n\n", + " if (max_num < m):\n", + " max_num = m\n", + " elif(m < min_num):\n", + " min_num = m\n", + " elif(m == 0):\n", + " break\n", + "print('最大值是:', max_num)\n", + "print('最小值是:', min_num)\n", + "print('平均值是:', ave)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入要输入的整数个数,回车结束。3\n", + "请输入一个整数,回车结束34\n", + "请输入一个整数,回车结束23\n", + "请输入一个整数,回车结束12\n", + "最大值是: 34\n", + "最小值是: 12\n", + "平均值是: 23.0\n" + ] + } + ], + "source": [ + "m = int(input('请输入要输入的整数个数,回车结束。'))\n", + "\n", + "max_number = int(input('请输入一个整数,回车结束'))\n", + "min_number = max_number\n", + "\n", + "total = max_number\n", + "\n", + "i = 1\n", + "while i < m:\n", + " i += 1\n", + " n = int(input('请输入一个整数,回车结束'))\n", + " total += n\n", + " if n > max_number:\n", + " max_number = n\n", + " elif n < min_number:\n", + " min_number = n\n", + " \n", + "print('最大值是:', max_number)\n", + "print('最小值是:', min_number)\n", + "print('平均值是:', total/m)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198580/he.txt b/8-10/201721198580/he.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/8-10/201721198580/he.txt @@ -0,0 +1 @@ + diff --git a/8-10/201721198580/hello.py b/8-10/201721198580/hello.py new file mode 100644 index 00000000..a8fe6ca0 --- /dev/null +++ b/8-10/201721198580/hello.py @@ -0,0 +1,2 @@ +name=input(); +print('Hello,', name); \ No newline at end of file diff --git a/8-10/201721198580/test.html b/8-10/201721198580/test.html new file mode 100644 index 00000000..e61ef7b9 --- /dev/null +++ b/8-10/201721198580/test.html @@ -0,0 +1 @@ +aa diff --git a/8-10/201721198581/2.ipynb b/8-10/201721198581/2.ipynb new file mode 100644 index 00000000..e99cc61d --- /dev/null +++ b/8-10/201721198581/2.ipynb @@ -0,0 +1,207 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# ex1" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I`m OK.\n" + ] + } + ], + "source": [ + "print('I`m OK.')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#(已运行ex1.py 脚本文件;交互模式已完成)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# $2.8 练习1 打印n!" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。6\n", + "720\n" + ] + } + ], + "source": [ + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "i = 1\n", + "product = 1\n", + "\n", + "while i < n:\n", + " i = i + 1\n", + " product = product * i\n", + " \n", + "print(product)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 练习2 写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你所求和的整数个数,以回车结束。3\n", + "请输入一个正整数,以回车结束。1\n", + "请输入一个正整数,以回车结束。2\n", + "请输入一个正整数,以回车结束。3\n", + "n个数的和是: 6\n" + ] + } + ], + "source": [ + "number = int(input('请输入你所求和的整数个数,以回车结束。'))\n", + "n = number\n", + "\n", + "i = 0\n", + "total = 0\n", + "while i < n:\n", + " i = i + 1\n", + " m = int(input('请输入一个正整数,以回车结束。'))\n", + " total = total + m\n", + "\n", + "print('n个数的和是:', total)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 练习3:用户可以输入的任意多个数字,直到用户不想输入为止。" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,并回车;若要停止输入,请输入q。2\n", + "请输入一个正整数,并回车;若要停止输入,请输入q。44\n", + "请输入一个正整数,并回车;若要停止输入,请输入q。5\n", + "请输入一个正整数,并回车;若要停止输入,请输入q。1\n", + "请输入一个正整数,并回车;若要停止输入,请输入q。q\n" + ] + } + ], + "source": [ + "m = input('请输入一个正整数,并回车;若要停止输入,请输入q。')\n", + "while m != 'q':\n", + " m = input('请输入一个正整数,并回车;若要停止输入,请输入q。')\n", + "if m == 'q':\n", + " exit()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 练习4:用户可以输入的任意多个数字,直到输入所有数字的和比当前输入数字小,且输入所有数字的积比当前输入数字的平方大。" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pls input a positive number:9\n", + "pls input a positive number:407\n", + "pls input a positive number:367\n", + "pls input a positive number:837\n" + ] + } + ], + "source": [ + "total = 0\n", + "product = 1\n", + "m = int(input('pls input a positive number:'))\n", + "square = m * m\n", + "while 1:\n", + " if total < m and product > square:\n", + " break\n", + " \n", + " total = total + m\n", + " product = product * m\n", + " square = m * m\n", + " m = int(input('pls input a positive number:'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198581/3.ipynb b/8-10/201721198581/3.ipynb new file mode 100644 index 00000000..fc3a4814 --- /dev/null +++ b/8-10/201721198581/3.ipynb @@ -0,0 +1,274 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# $3.6 练习1 由键盘读入用户姓名例如Mr. right,让用户输入出生的月份与日期,判断用户星座,假设用户是金牛座,则输出,Mr. right,你是非常有性格的金牛座!。" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的姓名,以回车结束。杨丽雪\n", + "请输入你出生的月份,以回车结束。12\n", + "请输入你出生的日期,以回车结束。28\n", + "杨丽雪 谨慎谦逊摩羯座\n" + ] + } + ], + "source": [ + "name = input('请输入你的姓名,以回车结束。')\n", + "month = int(input('请输入你出生的月份,以回车结束。'))\n", + "day = int(input('请输入你出生的日期,以回车结束。'))\n", + "if (month == 12 and day >= 22) or (month == 1 and day <= 19):\n", + " print(name,'谨慎谦逊摩羯座')\n", + "elif (month == 1 and day >= 20) or (month == 2 and day <= 18):\n", + " print(name,'创意十足水瓶座')\n", + "elif (month == 2 and day >= 19) or (month == 3 and day <= 20):\n", + " print(name,'善解人意双鱼座')\n", + "elif (month == 3 and day >= 21) or (month == 4 and day <= 19):\n", + " print(name,'坦白率真白羊座')\n", + "elif (month == 4 and day >= 20) or (month == 5 and day <= 20):\n", + " print(name,'脚踏实地金牛座')\n", + "elif (month == 5 and day >= 21) or (month == 6 and day <= 21):\n", + " print(name,'足智多谋双子座')\n", + "elif (month == 6 and day >= 22) or (month == 7 and day <= 22):\n", + " print(name,'亲切温暖巨蟹座')\n", + "elif (month == 7 and day >= 23) or (month == 8 and day <= 22):\n", + " print(name,'热情开朗狮子座')\n", + "elif (month == 8 and day >= 23) or (month == 9 and day <= 22):\n", + " print(name,'勤奋努力处女座')\n", + "elif (month == 9 and day >= 23) or (month == 10 and day <= 23):\n", + " print(name,'能屈能伸天秤座')\n", + "elif (month == 10 and day >= 24) or (month == 11 and day <= 22):\n", + " print(name,'深谋远虑天蝎座')\n", + "elif (month == 11 and day >= 23) or (month == 12 and day <= 21):\n", + " print(name,'正直坦率射手座')\n", + "else:\n", + " print('你好', name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 练习2: 由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。6\n", + "请输入一个正整数且不等于0,以回车结束。2\n", + "你想做什么运算?请输入“求和”或“乘积”或“取余”或“整除”,以回车结束。整除\n", + "整除为: 3\n" + ] + } + ], + "source": [ + "m = int(input('请输入一个正整数,以回车结束。'))\n", + "n = int(input('请输入一个正整数且不等于0,以回车结束。'))\n", + "op = input('你想做什么运算?请输入“求和”或“乘积”或“取余”或“整除”,以回车结束。')\n", + "if (op == '求和'):\n", + " print('和为:',m+n)\n", + "elif (op == '乘积'):\n", + " print('积为:',m*n)\n", + "elif (op == '取余'):\n", + " print('余数为:',m%n)\n", + "else:\n", + " print('整除为:',m//n)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 练习3: 根据北京雾霾PM2.5数值给出对应的防护建议。如当PM2.5数值大于500,则应该打开空气净化器,戴防雾霾口罩等。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入北京雾霾PM2.5值,以回车结束。17\n", + "优,空气很好,可以外出活动,呼吸新鲜空气。\n" + ] + } + ], + "source": [ + "PM = int(input('请输入北京雾霾PM2.5值,以回车结束。'))\n", + "if PM > 0 and PM <=50:\n", + " print('优,空气很好,可以外出活动,呼吸新鲜空气。')\n", + "elif PM > 50 and PM <= 100:\n", + " print('良,可以正常在户外活动,易敏感人群应减少外出。')\n", + "elif PM > 100 and PM <=150:\n", + " print('轻度污染,敏感人群减少体力消耗大的户外活动')\n", + "elif PM > 150 and PM <=200:\n", + " print('中度污染,对敏感人群影响较大')\n", + "elif PM > 200 and PM <= 300:\n", + " print('重度污染,所有人应适当减少室外活动')\n", + "elif PM > 300 and PM <= 500:\n", + " print('严重污染,尽量不要留在室外')\n", + "elif PM > 500:\n", + " print('非常严重,应该打开空气净化器,戴防雾霾口罩')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 练习 4:英文单词单数转复数;提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个英文单词(单数形式),以回车结束。leaf\n", + "改 f 或 fe为 ve,再加 s\n" + ] + } + ], + "source": [ + "word = input('请输入一个英文单词(单数形式),以回车结束。')\n", + "if word.endswith('s') or word.endswith('x') or word.endswith('z') or word.endswith('ch') or word.endswith('sh'):\n", + " print (word,'es',sep = '')\n", + "elif word.endswith('f') or word.endswith('fe'):\n", + " print('改 f 或 fe为 ve,再加 s')\n", + "elif word.endswith('y'):\n", + " trans = word.maketrans('y','i')\n", + " print(word.translate(trans),'es',sep = '')\n", + "elif word.endswith('o'):\n", + " if word == 'hero' or word == 'tomato' or word == 'potato':\n", + " print (word,'es',sep = '')\n", + "else:\n", + " print (word,'s',sep = '')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# 尝试性练习:写程序,能够在屏幕上显示空行。" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "begin\n", + "\n", + "end\n" + ] + } + ], + "source": [ + "print('begin')\n", + "print()\n", + "print('end')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 挑战性练习:写程序,由用户输入一些整数,能够得到几个整数中的次大值(第二大的值)并输出。" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入要输入的整数个数,回车结束。4\n", + "请输入一个整数,回车结束20\n", + "请输入一个整数,回车结束8\n", + "请输入一个整数,回车结束6\n", + "请输入一个整数,回车结束3\n", + "从大到小排序: [20, 8, 6, 3]\n", + "次大值是: 8\n" + ] + } + ], + "source": [ + "m = int(input('请输入要输入的整数个数,回车结束。'))\n", + "\n", + "alist = []\n", + "\n", + "i = 0\n", + "while i < m:\n", + " i += 1\n", + " n = int(input('请输入一个整数,回车结束'))\n", + " alist.append(n)\n", + "alist.sort(reverse = True)\n", + "print('从大到小排序:',alist)\n", + "del alist[0]\n", + "print('次大值是:', max(alist))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198581/me b/8-10/201721198581/me new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/8-10/201721198581/me @@ -0,0 +1 @@ + diff --git a/8-10/201721198582/2.ipynb b/8-10/201721198582/2.ipynb new file mode 100644 index 00000000..1c041615 --- /dev/null +++ b/8-10/201721198582/2.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。3\n", + "请输入一个正整数,以回车结束。1\n", + "请输入一个正整数,以回车结束。2\n", + "请输入一个正整数,以回车结束。3\n", + "6\n" + ] + } + ], + "source": [ + "#练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。\n", + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "i = 0\n", + "total = 0\n", + "\n", + "while i < n:\n", + " i = i + 1\n", + " m = int(input('请输入一个正整数,以回车结束。'))\n", + " total = total + m\n", + " \n", + "print(total)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。5\n", + "120\n" + ] + } + ], + "source": [ + "#练习1:仿照任务2完整代码,打印n!\n", + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "i = 0\n", + "total = 1\n", + "\n", + "while i < n:\n", + " i = i + 1\n", + " total = total * i\n", + " \n", + "print(total)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入任意数字直到#为止\n", + "输入整数(以回车结束)2\n", + "2\n", + "输入整数(以回车结束)5\n", + "5\n", + "输入整数(以回车结束)#\n", + "#\n" + ] + } + ], + "source": [ + "#练习3:用户可以输入的任意多个数字,直到用户不想输入为止。\n", + "print('输入任意数字直到#为止')\n", + "n=1\n", + "while n!='#':\n", + " n = input('输入整数(以回车结束)')\n", + " print(n)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。2\n", + "请输入一个正整数,以回车结束。5\n", + "请输入一个正整数,以回车结束。100\n", + "请输入一个正整数,以回车结束。500\n", + "条件满足\n" + ] + } + ], + "source": [ + "#练习4:用户可以输入的任意多个数字,直到: 输入所有数字的和比当前输入数字小,且输入所有数字的积大于500。\n", + "total = 0\n", + "product=1\n", + "while 1:\n", + " n = int(input('请输入一个正整数,以回车结束。'))\n", + " if total500:\n", + " break\n", + " total = total + n\n", + " product=product * n\n", + "print('条件满足')\n", + " \n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198582/3.ipynb b/8-10/201721198582/3.ipynb new file mode 100644 index 00000000..79c18e98 --- /dev/null +++ b/8-10/201721198582/3.ipynb @@ -0,0 +1,130 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入计算式以#结束\n", + "输入计算符+\n", + "输入第一个整数2\n", + "输入第二个整数(第二个数大于第一个数)5\n", + "14\n", + "输入计算符*\n", + "输入第一个整数2\n", + "输入第二个整数(第二个数大于第一个数)5\n", + "120\n", + "输入计算符%\n", + "输入第一个整数2\n", + "输入第二个整数(第二个数大于第一个数)5\n", + "2\n", + "输入计算符9\n", + "输入第一个整数2\n", + "输入第二个整数(第二个数大于第一个数)5\n", + "0.4\n", + "输入计算符#\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出\n", + "print('输入计算式以#结束')\n", + "p=input('输入计算符')\n", + "while p!='#':\n", + " m=int(input('输入第一个整数'))\n", + " n=int(input('输入第二个整数(第二个数大于第一个数)'))\n", + " t=n-m+1\n", + " i=0\n", + " total=0\n", + " proudct=1\n", + " if p=='+':\n", + " while i n**2):\n", + " break\n", + " mul = mul * n \n", + " sum = sum + n \n", + " n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "print('total:', sum)\n", + "print('mul:', mul)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198584/3.ipynb b/8-10/201721198584/3.ipynb new file mode 100644 index 00000000..1162706f --- /dev/null +++ b/8-10/201721198584/3.ipynb @@ -0,0 +1,136 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "作业3 控制语句" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数m,以回车结束。1\n", + "请输入一个整数m,以回车结束。5\n", + "你好,如果计算从m到n的和,请输入1;如果计算从m到n的积,请输入2;如果计算m除以n的余数的值,请输入3;如果计算m整除n的值,请输入4。以回车结束 \n", + "选择:2\n", + "1 到 5 的积为: 120\n" + ] + } + ], + "source": [ + "#练习2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,\n", + "#如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "\n", + "m = int(input('请输入一个整数m,以回车结束。'))\n", + "n = int(input('请输入一个整数m,以回车结束。'))\n", + "print('你好,如果计算从m到n的和,请输入1;如果计算从m到n的积,请输入2;如果计算m除以n的余数的值,请输入3;如果计算m整除n的值,请输入4。以回车结束 ')\n", + "i = int(input('选择:'))\n", + "if i == 1:\n", + " j = m\n", + " Sum = 0\n", + " while j <= n:\n", + " Sum += j\n", + " j = j + 1\n", + " print (m,'到',n,'的和为:',Sum)\n", + "elif i == 2:\n", + " j = m\n", + " Mul = 1\n", + " while j <= n:\n", + " Mul *=j\n", + " j = j + 1\n", + " print (m,'到',n,'的积为:',Mul)\n", + "elif i == 3:\n", + " rem = m % n\n", + " print (m,'除以',n,'的余数为:',rem)\n", + "elif i == 4:\n", + " rem = m / n\n", + " print (m,'除以',n,'的结果为:',rem)\n", + "else:\n", + " print('请注意正确输入!')\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个英文名词(回车结束):apple\n", + "apple 的复数为: apples\n" + ] + } + ], + "source": [ + "#练习4;英文单词单数转复数,要求输入一个英文名词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议\n", + "#(提示,some_string.(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。\n", + "\n", + "def IsNotForeignWord(n):\n", + " return 1\n", + "RemainArr = ('fish','sheep','cattle','deer','salmon')\n", + "\n", + "n = input('请输入一个英文名词(回车结束):')\n", + "if n in RemainArr :\n", + " n1 = n\n", + "elif n.endswith(('y')):\n", + " YuanArr = ('a','e','i','o','u')\n", + " if n[-2] not in YuanArr :\n", + " n1 = n[:-1] + 'ies'\n", + "elif n.endswith(('o')):\n", + " if IsNotForeignWord(n):\n", + " n1 = n + 'es'\n", + " else :\n", + " n1 = n + 's'\n", + "elif n.endswith(('f')):\n", + " n1 = n[:-1] + 'ves'\n", + "elif n.endswith(('fe')):\n", + " n1 = n[:-2] + 'ves'\n", + "elif n.endswith(('us')):\n", + " n1 = n[:-2] + 'i'\n", + "elif n.endswith(('is')):\n", + " n1 = n[:-2] + 'es'\n", + "elif n.endswith(('ix')):\n", + " n1 = n[:-2] + 'ices'\n", + "elif n.endswith(('a')):\n", + " n1 = n + 'e'\n", + "elif n.endswith(('s','z','x')) or n.endswith(('ch','sh')):\n", + " n1 = n + 'es'\n", + "else :\n", + " n1 = n + 's'\n", + "print (n,'的复数为:',n1)\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198591/2.ipynb b/8-10/201721198591/2.ipynb new file mode 100644 index 00000000..ffafb08a --- /dev/null +++ b/8-10/201721198591/2.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数n:5\n", + "120\n" + ] + } + ], + "source": [ + "#练习1:仿照任务2完整代码,打印n!。\n", + "n = int(input(\"请输入一个正整数n:\"))\n", + "sum = 1\n", + "while n > 0:\n", + "\tsum *= n\n", + "\tn = n-1\n", + "print(sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你想输入的正整数的个数:4\n", + "请输入第1个整数:43\n", + "请输入第2个整数:56\n", + "请输入第3个整数:845\n", + "请输入第4个整数:9\n", + "这些数的和是:953\n" + ] + } + ], + "source": [ + "#练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。\n", + "n = int(input(\"请输入你想输入的正整数的个数:\"))\n", + "sum = 0\n", + "i = 1\n", + "while n > 0:\n", + "\ta = int(input(\"请输入第%d个整数:\"%i))\n", + "\ti += 1\n", + "\tn -= 1\n", + "\tsum += a\n", + "print(\"这些数的和是:%d\"% sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入第一个你想输入的数字,不想输入请输入end:345\n", + "请输入第2个数字:345\n", + "请输入第3个数字:4\n", + "请输入第4个数字:end\n" + ] + } + ], + "source": [ + "#练习3:用户可以输入的任意多个数字,直到用户不想输入为止。\n", + "\n", + "i = 2\n", + "a = input('请输入第一个你想输入的数字,不想输入请输入end:')\n", + "while a != 'end':\n", + "\ta = input(\"请输入第%d个数字:\"%i)\n", + "\ti += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入第1个整数:2\n", + "请输入第2个整数:3\n", + "请输入第3个整数:4\n", + "请输入第4个整数:5\n", + "请输入第5个整数:6\n", + "请输入第6个整数:7\n", + "请输入第7个整数:8\n", + "请输入第8个整数:100\n", + "输入结束,所有数字和为:135,所有数字积为:4032000\n" + ] + } + ], + "source": [ + "#练习4:用户可以输入的任意多个数字,直到: 输入所有数字的和比当前输入数字小,且输入所有数字的积大于500。\n", + "sum = 0\n", + "product = 1\n", + "i = 1\n", + "flag = True\n", + "while flag:\n", + "\ta = int(input(\"请输入第%d个整数:\"%i))\n", + "\ti += 1\n", + "\tif sum < a and product > 500:\n", + "\t\t\n", + "\t\tflag = False\n", + "\tproduct *= a\n", + "\tsum += a\n", + "print('输入结束,所有数字和为:%d,所有数字积为:%d' % (sum,product))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198591/3.ipynb b/8-10/201721198591/3.ipynb new file mode 100644 index 00000000..9b0c1baf --- /dev/null +++ b/8-10/201721198591/3.ipynb @@ -0,0 +1,111 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入整数m:7\n", + "请输入整数n(不为0):4\n", + "若您想求和请输入1\n", + "求积请输入2\n", + "求余数请输入3\n", + "求整除请输入4\n", + "1\n", + "m到n的和为:22\n" + ] + } + ], + "source": [ + "'''\n", + "练习 2: 写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要\n", + "乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "'''\n", + "\n", + "m = int(input(\"请输入整数m:\"))\n", + "n = int(input(\"请输入整数n(不为0):\"))\n", + "x = int(input(\"若您想求和请输入1\\n求积请输入2\\n求余数请输入3\\n求整除请输入4\\n\"))\n", + "if x == 1:\n", + " sum = 0\n", + " if m > n:\n", + " tmp = m\n", + " m = n\n", + " n = tmp\n", + " while m <= n:\n", + " sum += n\n", + " n -= 1\n", + " print(\"m到n的和为:%d\"%sum)\n", + "elif x == 2:\n", + " product = 1\n", + " if m > n:\n", + " tmp = m\n", + " m = n\n", + " n = tmp\n", + " while m <= n:\n", + " product *= n\n", + " n -= 1\n", + " print(\"m到n的积为:%d\"%product)\n", + "elif x == 3:\n", + " print(\"m除以n的余数为:\",m%n)\n", + "elif x== 4:\n", + " print(\"m整除n的结果为:\",m/n)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个单词:leaf\n", + "leaves\n" + ] + } + ], + "source": [ + "'''\n", + "练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议(提示,\n", + "some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。\n", + "'''\n", + "str = input(\"请输入一个单词:\")\n", + "length = len(str)\n", + "if str.endswith('s') or str.endswith('ch') or str.endswith('x') or str.endswith('sh'):\n", + " print(str+'es')\n", + "elif str.endswith('f'):\n", + " print(str[0:length-1]+'ves')\n", + "elif str.endswith('fe'):\n", + " print(str[0:length-2]+'ves')\n", + "else:\n", + " print(str+'s')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198591/readme.md b/8-10/201721198591/readme.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/8-10/201721198591/readme.md @@ -0,0 +1 @@ + diff --git a/8-10/201721198593/2.ipynb b/8-10/201721198593/2.ipynb new file mode 100644 index 00000000..b21a12f0 --- /dev/null +++ b/8-10/201721198593/2.ipynb @@ -0,0 +1,210 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 作业2.md" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 练习1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "仿照任务2完整代码,打印n!。" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。4\n", + "24\n" + ] + } + ], + "source": [ + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "i = 0\n", + "total = 1\n", + "\n", + "while i < n:\n", + " i = i + 1\n", + " total = total * i\n", + " \n", + "print(total)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 练习2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数,以回车结束。4\n", + "请输入任意整数,以回车结束1\n", + "请输入任意整数,以回车结束2\n", + "请输入任意整数,以回车结束3\n", + "请输入任意整数,以回车结束4\n", + "10\n" + ] + } + ], + "source": [ + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "i = 0\n", + "total = 0\n", + "\n", + "\n", + "while ip or total<500:\n", + " i += q\n", + " total *= p\n", + " p = int(input('请输入任意整数,以回车结束'))\n", + " q=p\n", + " \n", + "print(total)\n", + "print(i)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198593/3.ipynb b/8-10/201721198593/3.ipynb new file mode 100644 index 00000000..ebea22f3 --- /dev/null +++ b/8-10/201721198593/3.ipynb @@ -0,0 +1,130 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 作业3.md\n", + "## 练习2\n", + "写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入任意整数给m,以回车结束12\n", + "请输入任意整数给n,以回车结束8\n", + "您想操作的是:求和键入1、求乘积键入2,、求余数键入3;如果键入其他值将求整除3\n", + "4\n" + ] + } + ], + "source": [ + "m = int(input('请输入任意整数给m,以回车结束'))\n", + "n = int(input('请输入任意整数给n,以回车结束'))\n", + "i = int(input('您想操作的是:求和键入1、求乘积键入2,、求余数键入3;如果键入其他值将求整除'))\n", + "h = 0\n", + "total = 0\n", + "if i == 1:\n", + " if m > n:\n", + " h=m\n", + " m=n\n", + " n=h\n", + " while m<=n:\n", + " total = total + m \n", + " m = m + 1\n", + "elif i == 2:\n", + " if m > n:\n", + " h=m\n", + " m=n\n", + " n=h\n", + " while m<=n:\n", + " total = total * m \n", + " m = m + 1\n", + "elif i == 3:\n", + " if n > m:\n", + " h=m\n", + " m=n\n", + " n=h\n", + " total = m%n\n", + "else:\n", + " if n > m:\n", + " h=m\n", + " m=n\n", + " n=h\n", + " total = m/n\n", + "print(total)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 练习4\n", + "英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入任意英文动词,以回车结束wish\n", + "wishes\n" + ] + } + ], + "source": [ + "word = input('请输入任意英文动词,以回车结束')\n", + "if word.endswith('y'): \n", + " print(word[:-1] + 'ies') \n", + "elif word[-1] in 'sx' or word[-2:] in ['sh', 'ch']: \n", + " print(word + 'es') \n", + "elif word.endswith('an'): \n", + " print(word[:-2] + 'en') \n", + "else: \n", + " print(word + 's') " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198595/2.ipynb b/8-10/201721198595/2.ipynb new file mode 100644 index 00000000..6f2c6904 --- /dev/null +++ b/8-10/201721198595/2.ipynb @@ -0,0 +1,150 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数,回车结束3\n", + "6\n" + ] + } + ], + "source": [ + "#练习1打印n!\n", + "n=int(input('请输入一个整数,回车结束'))\n", + "i=1\n", + "sum=1\n", + "while i i or mul < 500:\n", + " \n", + " sum+=i\n", + " mul*=i\n", + " print(\"sum=\"+str(sum-1))\n", + " print(\"mul=\"+str(mul))\n", + " i=int(input(\"请输入数字\"))\n", + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198595/3.ipynb b/8-10/201721198595/3.ipynb new file mode 100644 index 00000000..215f6c6c --- /dev/null +++ b/8-10/201721198595/3.ipynb @@ -0,0 +1,131 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入整数m=5\n", + "请输入整数n(n不为0)=2\n", + "请选择你要执行的操作 输入1:求m到n的和 2:求m到n的积 3:求m除以n的余数3\n", + "选择为3\n", + "m除以n的余数为2\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,\n", + "#如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "\n", + "m=input(\"请输入整数m=\")\n", + "\n", + "n=input(\"请输入整数n(n不为0)=\")\n", + "m=int(m)\n", + "n=int(n)\n", + "#n如果输入为0就一直重新输入,直到不为0\n", + "while n==0 :\n", + " n=input(\"请输入整数n(n不为0)=\")\n", + " n=int(n)\n", + "tmp=input(\"请选择你要执行的操作 输入1:求m到n的和 2:求m到n的积 3:求m除以n的余数\")\n", + "tmp=int(tmp)\n", + "\n", + "print(\"选择为\"+str(tmp))\n", + "if tmp == 1 :\n", + " if m-n>0:\n", + " i=n\n", + " sum=0\n", + " while i<=m :\n", + " sum+=i\n", + " i+=1\n", + " else:\n", + " i=m\n", + " sum=0\n", + " while i<=n :\n", + " sum+=i\n", + " i+=1\n", + " print(\"m到n和为\"+str(sum))\n", + "elif tmp == 2 :\n", + " if m-n>0:\n", + " i=n\n", + " mul=1\n", + " while i<=m :\n", + " mul*=i\n", + " i+=1\n", + " else:\n", + " i=m\n", + " mul=1\n", + " while i<=n :\n", + " mul*=i\n", + " i+=1\n", + " print(\"m到n积为\"+str(mul))\n", + "elif tmp == 3 :\n", + " print(\"m除以n的余数为\"+str(m//n))\n", + "else:\n", + " print(\"输入有误\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个英文名词(单数形式)woman\n", + "woman的复数形式women\n" + ] + } + ], + "source": [ + "#练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议\n", + "#(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),\n", + "#liupengyuan'.endswith('n'))。\n", + "word= input(\"请输入一个英文名词(单数形式)\")\n", + "\n", + "if word.endswith('s') or word.endswith('x') or word.endswith('ch') or word.endswith('sh') :\n", + " print (word+\"的复数形式\"+word+\"es\")\n", + "elif word.endswith('y') and not word.endswith('ay') and not word.endswith('ey') and not word.endswith('iy') and not word.endswith('oy') and not word.endswith('uy') :\n", + " print (word+\"的复数形式\"+word[0:-1]+\"ies\")\n", + "elif word.endswith('f') :\n", + " print (word+\"的复数形式\"+word[0:-1]+\"ves\")\n", + "elif word.endswith('fe') :\n", + " print (word+\"的复数形式\"+word[0:-2]+\"ves\")\n", + "elif word.endswith('o') :\n", + " print (word+\"的复数形式\"+word+\"es\")\n", + "elif word.endswith('man') :\n", + " print (word+\"的复数形式\"+word[0:-3]+\"men\")\n", + "else :\n", + " print (word+\"的复数形式\"+word+\"s\")\n", + " \n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198596/2.ipynb b/8-10/201721198596/2.ipynb new file mode 100644 index 00000000..0a27e377 --- /dev/null +++ b/8-10/201721198596/2.ipynb @@ -0,0 +1,235 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#2.8 练习一: 仿照任务2完整代码,打印n!。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please Enter The Number:125\n", + "n!= 188267717688892609974376770249160085759540364871492425887598231508353156331613598866882932889495923133646405445930057740630161919341380597818883457558547055524326375565007131770880000000000000000000000000000000\n" + ] + } + ], + "source": [ + "n = int(input('Please Enter The Number:'))\n", + "\n", + "multi = 1\n", + "i = 1\n", + "\n", + "while i<=n:\n", + " multi = multi*i\n", + " i+=1\n", + "print('n!=',multi)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#实践1:键入如下代码并观察执行结果。" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的姓名,以回车结束。刘晓\n", + "你好! 刘晓\n", + "请输入一个正整数,以回车结束。12\n", + "请输入一个正整数,以回车结束。15\n", + "两个数的和是: 27\n", + "再见! 刘晓\n" + ] + } + ], + "source": [ + "name = input('请输入你的姓名,以回车结束。')\n", + "print('你好!', name)\n", + "\n", + "n = int(input('请输入一个正整数,以回车结束。'))\n", + "m = int(input('请输入一个正整数,以回车结束。'))\n", + "\n", + "print('两个数的和是:', m+n)\n", + "print('再见!', name)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# 练习2:仿照实践1,写出由用户指定整数个数,并由用户输入多个整数,并求和的代码。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入整数个数:5\n", + "请输入一个整数:7\n", + "请输入一个整数:17\n", + "请输入一个整数:27\n", + "请输入一个整数:37\n", + "请输入一个整数:47\n", + "5 个整数之和是: 135\n" + ] + } + ], + "source": [ + "n = int(input('请输入整数个数:'))\n", + "\n", + "total = 0\n", + "i= 0\n", + "\n", + "while inum2**2):\n", + " print('满足条件,退出!')\n", + " break\n", + " \n", + "print('total=',total)\n", + "print('multi=',multi)\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198596/3.ipynb b/8-10/201721198596/3.ipynb new file mode 100644 index 00000000..c79fb34c --- /dev/null +++ b/8-10/201721198596/3.ipynb @@ -0,0 +1,134 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#3.6 练习 2:\n", + "#写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,\n", + "#如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个整数:7\n", + "请输入一个不为0的整数:17\n", + "请输入你想对数字进行的运算,如+-*/%//\n", + "对m,n计算的结果位: 0.4117647058823529\n" + ] + } + ], + "source": [ + "m = int(input('请输入一个整数:'))\n", + "n = int(input('请输入一个不为0的整数:'))\n", + "if m<=n:\n", + " max_number = n\n", + " min_number = m\n", + "else:\n", + " max_number = m\n", + " min_number = n\n", + " \n", + "i = min_number\n", + "result =0\n", + "\n", + "op = input('请输入你想对数字进行的运算,如+-*/%')\n", + "\n", + "if op == \"+\":\n", + " for i in range(min_number,max_number+1):\n", + " result+=i\n", + " i+=1\n", + "elif op == \"-\":\n", + " for i in range(min_number,max_number+1):\n", + " result-=i\n", + "elif op == \"*\":\n", + " for i in range(min_number,max_number+1):\n", + " result*=i\n", + "elif op == \"%\":\n", + " result = m%n\n", + "elif op == \"//\":\n", + " result = m/n\n", + "\n", + "print('对m,n计算的结果位:',result)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "#练习 4:英文单词单数转复数,要求输入一个英文动词(单数形式),能够得到其复数形式,或给出单数转复数形式的建议\n", + "#(提示,some_string.endswith(some_letter)函数可以判断某字符串结尾字符,可尝试运行:'myname'.endswith('me'),liupengyuan'.endswith('n'))。" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个英文单词(单数形式):family\n", + "family 的复数形式是: families\n" + ] + } + ], + "source": [ + "word = input('请输入一个英文单词(单数形式):')\n", + "\n", + "if word ==\"potato\" or word ==\"tomato\":\n", + " print(word,\"的复数形式是:\",word + 's')\n", + "elif word.endswith('s') or word.endswith('o') or word.endswith('x') or word.endswith('ch') or word.endswith('sh'):\n", + " print(word,\"的复数形式是:\",word + 'es')\n", + "elif word.endswith('y'):\n", + " print(word,\"的复数形式是:\",word[:-1] + 'ies')\n", + "elif word.endswith('f'):\n", + " print(word,\"的复数形式是:\",word[:-1] + 'ves')\n", + "elif word.endswith('fe'):\n", + " print(word,\"的复数形式是:\",word[:-2] + 'ves')\n", + "elif word.endswith('an'): \n", + " print(word,\"的复数形式是:\",word[:-2] + 'en')\n", + "else:\n", + " print(word,\"的复数形式是:\",word[:-2] + 's')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198597/2.ipynb b/8-10/201721198597/2.ipynb new file mode 100644 index 00000000..2b569e16 --- /dev/null +++ b/8-10/201721198597/2.ipynb @@ -0,0 +1,176 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#2.8练习一" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入一个正整数:10\n", + "n!= 3628800\n" + ] + } + ], + "source": [ + "n=input('请输入一个正整数:')\n", + "n=int(n)\n", + "\n", + "i=1\n", + "total=1\n", + "\n", + "while i<=n:\n", + " total=i*total\n", + " i=i+1\n", + "print('n!=',total)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#练习2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "指定求和整数的个数:4\n", + "请输入一个正整数,以回车结束3\n", + "请输入一个正整数,以回车结束13\n", + "请输入一个正整数,以回车结束2\n", + "请输入一个正整数,以回车结束15\n", + "求和值为: 33\n" + ] + } + ], + "source": [ + "a = int(input('指定求和整数的个数:'))\n", + "i=0\n", + "total=0\n", + "while i500):\n", + " print('输入所有数字的和比当前输入数字小,且输入所有数字的积大于500')\n", + " break \n", + "print('和为:',total)\n", + "print('乘积为:',pro)\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198597/3.ipynb b/8-10/201721198597/3.ipynb new file mode 100644 index 00000000..568741d5 --- /dev/null +++ b/8-10/201721198597/3.ipynb @@ -0,0 +1,127 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#3.6 练习2" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入一个整数m 10\n", + "输入一个不为0的整数n 5\n", + "请选择求和、乘积、余数或整数 乘积\n", + "m和n的运算结果为: 151200\n" + ] + } + ], + "source": [ + "n=int(input('输入一个整数m '))\n", + "m=int(input('输入一个不为0的整数n '))\n", + "if m<=n:\n", + " max=n\n", + " min=m\n", + "else:\n", + " max=m\n", + " min=n\n", + "result=min\n", + "a=input('请选择求和、乘积、余数或整数 ')\n", + "if a=='求和':\n", + " while min0:\n", + " i=int(input(\"输入一个整数,回车结束:\"))\n", + " sum+=i\n", + " num-=1\n", + "print(\"以上整数的和为:\",sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入任意个数字,直到不想输入为止,\n", + "不想输入时请随意输入任何非数字的字符,程序会自动停止\n", + "输入一个数字:1\n", + "输入一个数字:2\n", + "输入一个数字:2.1\n", + "输入一个数字:0.3\n", + "输入一个数字:stop\n", + "程序结束\n" + ] + } + ], + "source": [ + "#练习3:用户可以输入的任意多个数字,直到用户不想输入为止。\n", + "num=0\n", + "print(\"输入任意个数字,直到不想输入为止,\\n不想输入时请随意输入任何非数字的字符,程序会自动停止\")\n", + "while True:\n", + " try:\n", + " num=float(input(\"输入一个数字:\"))\n", + " except Exception:\n", + " break\n", + "print(\"程序结束\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入一个数字,回车结束:-10\n", + "输入一个数字,回车结束:-300\n", + "程序结束!\n" + ] + } + ], + "source": [ + "#练习4:用户可以输入的任意多个数字,直到: 输入所有数字的和比当前输入数字小,且输入所有数字的积大于500。\n", + "num=0\n", + "he=0\n", + "ji=1\n", + "while True:\n", + " num=float(input(\"输入一个数字,回车结束:\"))\n", + " he+=num\n", + " ji*=num\n", + " if he500:\n", + " break\n", + "print(\"程序结束!\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198598/3.ipynb b/8-10/201721198598/3.ipynb new file mode 100644 index 00000000..528b5378 --- /dev/null +++ b/8-10/201721198598/3.ipynb @@ -0,0 +1,129 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "输入两个整数m和n\n", + "输入整数1:2\n", + "输入整数2:6\n", + "输入以下运算符号:\n", + "+ :代表求和\n", + "* :代表乘积\n", + "% :代表取余\n", + "/ :代表整除\n", + "*\n", + "n到m的乘积为: 720\n", + "程序结束!\n" + ] + } + ], + "source": [ + "#练习 2:写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,\n", + "#如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "num=0\n", + "he=0\n", + "ji=1\n", + "yu=0\n", + "chu=0\n", + "print(\"输入两个整数m和n\")\n", + "try:\n", + " m=int(input(\"输入整数1:\"))\n", + " n=int(input(\"输入整数2:\"))\n", + "except Exception as e:\n", + " print(e)\n", + "else:\n", + " if mm**2:\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'extract'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[1;32mfrom\u001b[0m \u001b[0mextract\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mextract\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'extract'" + ] + } + ], + "source": [ + "from extract import extract" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/8-10/201721198599/3.ipynb b/8-10/201721198599/3.ipynb new file mode 100644 index 00000000..8ae28098 --- /dev/null +++ b/8-10/201721198599/3.ipynb @@ -0,0 +1,186 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#练习1\n", + "import time\n", + "def zodiac(month, day): \n", + " zodiac_map = { \n", + " u'白羊座':[(3,21), (4,20)], \n", + " u'金牛座':[(4,21), (5,20)], \n", + " u'双子座':[(5,21), (6,21)], \n", + " u'巨蟹座':[(6,22), (7,22)], \n", + " u'狮子座':[(7,23), (8,22)], \n", + " u'处女座':[(8,23), (9,22)], \n", + " u'天秤座':[(9,23), (10,22)], \n", + " u'天蝎座':[(10,23), (11,21)], \n", + " u'射手座':[(11,23), (12,22)], \n", + " u'水瓶座':[(1,20), (2,18)], \n", + " u'双鱼座':[(2,19), (3,20)] \n", + " } \n", + " for k,v in zodiac_map.items(): \n", + " if v[0] <= (month,day) <= v[1]: \n", + " return k\n", + " if (month,day) >= (12,22) or (month,day) <= (1,19): \n", + " return u'摩羯座'" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入你的名字lmy\n", + "请输入你生日月份7\n", + "请输入你生日日期22\n", + "lmy,你是非常有性格的巨蟹座\n" + ] + } + ], + "source": [ + "name=str(input(\"请输入你的名字\"))\n", + "month=int(input(\"请输入你生日月份\"))\n", + "day=int(input(\"请输入你生日日期\"))\n", + "zodiac=zodiac(month,day)\n", + "print(name+\",\"+\"你是非常有性格的\"+zodiac+\"!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "请输入任意整数:3\n", + "请输入任意不为0的整数:5\n", + "请输入您要进行的操作,如输入+-/*%+\n", + "12\n" + ] + } + ], + "source": [ + "#练习2 \n", + "#写程序,可由键盘读入两个整数m与n(n不等于0),询问用户意图,如果要求和则计算从m到n的和输出,\n", + "#如果要乘积则计算从m到n的积并输出,如果要求余数则计算m除以n的余数的值并输出,否则则计算m整除n的值并输出。\n", + "m=int(input(\"请输入任意整数:\"))\n", + "n=int(input(\"请输入任意不为0的整数:\"))\n", + "result=0\n", + "op=input(\"请输入您要进行的操作,如输入+-/*%\")\n", + "if m>n:\n", + " max=m\n", + " min=n\n", + "else:\n", + " max=n\n", + " min=m\n", + "#max=m>n?m:n\n", + "#min=m