diff --git a/cyc.ipynb b/cyc.ipynb new file mode 100644 index 0000000..2c3e519 --- /dev/null +++ b/cyc.ipynb @@ -0,0 +1,81 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "version": "3.7.6-final" + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "police:110\n" + } + ], + "source": [ + "num = [110,'120','119']\n", + "institude = [\"police\",'hostpial','fireman']\n", + "print(\"{}:{}\".format(institude[0],num[0]))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "two\nliguozhong\n1720313118\n" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "4" + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "father = {\"name\":\"liguozhong\",\"job\":\"famer\",\"phone_num\":\"13855089513\"}\n", + "sister = {\"name\":\"lirongyuan\",\"job\":\"nurse\",\"phone_num\":\"1720313118\"}\n", + "father[\"list\"] = \"two\"\n", + "print(father[\"list\"])\n", + "print(father[\"name\"])\n", + "print(sister[\"phone_num\"])\n", + "len(father)\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/demo.ipynb b/demo.ipynb new file mode 100644 index 0000000..913c5d0 --- /dev/null +++ b/demo.ipynb @@ -0,0 +1,127 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "version": "3.7.6-final" + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "97" + }, + "metadata": {}, + "execution_count": 5 + } + ], + "source": [ + "ord('a')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "20013" + }, + "metadata": {}, + "execution_count": 6 + } + ], + "source": [ + "ord('中')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "'a'" + }, + "metadata": {}, + "execution_count": 7 + } + ], + "source": [ + "\n", + "chr(97)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "'中文'" + }, + "metadata": {}, + "execution_count": 8 + } + ], + "source": [ + "'\\u4e2d\\u6587'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "['hello', 'world', 'very']\n" + } + ], + "source": [] + } + ] +} \ No newline at end of file diff --git a/homework.ipynb b/homework.ipynb new file mode 100644 index 0000000..8b5c61f --- /dev/null +++ b/homework.ipynb @@ -0,0 +1,136 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "version": "3.7.6-final" + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "40.5摄氏度等于104.9华摄氏度\n" + } + ], + "source": [ + "def temp_c_change_temp_f(temp_c):#摄氏温度转换为华摄氏度函数\n", + " temp_f = temp_c*9/5 + 32\n", + " return(str(temp_c)+'摄氏度等于'+str(temp_f)+'华摄氏度')\n", + "\n", + "f = temp_c_change_temp_f(40.5)\n", + "print(f)\n", + " \n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "8 不是质数\n" + } + ], + "source": [ + "def handlerNum(num):#判断一个数是否为素数\n", + " # 质数大于 1\n", + " if num > 1:\n", + " for i in range(2, num//2+1):\n", + " if (num % i) == 0:\n", + " print(num,\"不是质数\")\n", + " break\n", + " else:\n", + " print(num, \"是质数\")\n", + "\n", + " # 如果输入的数字小于或等于 1,不是质数\n", + " else:\n", + " print(num, \"不是质数\")\n", + "if __name__ == '__main__':\n", + "\n", + " num = int(input(\"请输入一个数字: \"))\n", + " handlerNum(num)" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "123.0\n6.0\n" + } + ], + "source": [ + "#求数字中各位数之和\n", + "input_num = float(input(\"请输入一个数字\"))\n", + "while ( input_num*10% 10)!= 0:\n", + " input_num = input_num * 10\n", + "print(input_num)\n", + "input_num_remainder = input_num % 10\n", + "final_result = 0\n", + "while input_num_remainder != 0:\n", + " final_result = input_num_remainder+final_result\n", + " input_num = (input_num -input_num_remainder)/10\n", + " input_num_remainder = input_num % 10\n", + "print(final_result)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "[4, 7, 23, 56, 9, 0, 12, 3, 34, 45, 5, 6]\n" + } + ], + "source": [ + "one_list=[4,7,4,23,56,9,0,56,12,3,56,34,45,5,6,56]\n", + "temp_list=[] \n", + "for one in one_list: \n", + " if one not in temp_list: \n", + " temp_list.append(one) \n", + "print(temp_list)\n", + "\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/homework_new.ipynb b/homework_new.ipynb new file mode 100644 index 0000000..dcda63c --- /dev/null +++ b/homework_new.ipynb @@ -0,0 +1,140 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "version": "3.7.6-final" + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "40.5555666摄氏度等于105.00001988华摄氏度\n0摄氏度等于32.0华摄氏度\n" + } + ], + "source": [ + "def temp_c_to_temp_f(temp_c):#摄氏温度转换为华摄氏度函数\n", + " temp_f = temp_c*9/5 + 32\n", + " return(str(temp_c)+'摄氏度等于'+str(temp_f)+'华摄氏度')\n", + "\n", + "\n", + "\n", + "print (temp_c_to_temp_f(40.5555666))\n", + "print (temp_c_to_temp_f(0))\n", + " \n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "True\nTrue\nFalse\n" + } + ], + "source": [ + "def check_prime(num):#判断一个数是否为素数\n", + " cyc_factor = int(num/2+1)\n", + " # 质数大于 1\n", + " if num < 2:\n", + " return False \n", + " \n", + " for i in range(2, cyc_factor):\n", + " if (num % i) == 0:\n", + " return False\n", + " \n", + " return True \n", + "\n", + "\n", + "print(check_prime(2))\n", + "print(check_prime(5))\n", + "print(check_prime(6))\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "9\n15\n" + } + ], + "source": [ + "def Sum_Of_Each_Digit(num):\n", + " result = 0\n", + " for i in range(len(num)):\n", + " if(num[i]!='.'): \n", + " result = int(num[i]) + result\n", + " return result\n", + "\n", + "\n", + "print(Sum_Of_Each_Digit(str(12321)))\n", + "print(Sum_Of_Each_Digit(str(123.45)))\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": "[2, 1, 3, 4, 5, 'hello']\n" + } + ], + "source": [ + "def Remove_dup(one_list):\n", + "\n", + " temp_list=[] \n", + " for one in one_list: \n", + " if one not in temp_list: \n", + " temp_list.append(one) \n", + " return temp_list\n", + "\n", + "\n", + "one_list = [2,1,2,2,3,4,5,5,2.0,2.0,\"hello\",\"hello\"]\n", + "print(Remove_dup(one_list))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file