|
@@ -0,0 +1,274 @@
|
|
|
+{
|
|
|
+ "cells": [
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "9d496a34-c525-47a2-bc08-a132d0295be5",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "2\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "a=1+1\n",
|
|
|
+ "print(a)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "de78dde7-2bb7-4ac3-b8bd-97c0062a279f",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "ename": "",
|
|
|
+ "evalue": "",
|
|
|
+ "output_type": "error",
|
|
|
+ "traceback": [
|
|
|
+ "\u001b[1;31mRunning cells with 'c:\\Program Files\\Python39\\python.exe' requires the ipykernel package.\n",
|
|
|
+ "\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
|
|
|
+ "\u001b[1;31mCommand: '\"c:/Program Files/Python39/python.exe\" -m pip install ipykernel -U --user --force-reinstall'"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "c=111+222\n",
|
|
|
+ "print(c)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 19,
|
|
|
+ "id": "f7fa69b1-cc2a-4460-8601-e3b5e35f3626",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "##2.1.结构的控制"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 17,
|
|
|
+ "id": "427f925d-5db2-4554-9502-b873b3375463",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "hello\n",
|
|
|
+ "word\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "if False:\n",
|
|
|
+ " print(\"hello\")\n",
|
|
|
+ "elif True:\n",
|
|
|
+ " print(\"hello\")\n",
|
|
|
+ " print(\"word\")"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 18,
|
|
|
+ "id": "d2acf1bf-74dd-4bd0-87e3-4eff3098aee3",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "726\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "a=22*33\n",
|
|
|
+ "print(a)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "23c3fe61-246b-4837-af71-31e5921b3f11",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "## 2.2. 条件"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 26,
|
|
|
+ "id": "70293327-4778-46ca-aff3-237c5ceef229",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "请输入一个数: 336\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "\u001b[33;41m336是偶函数!\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "num = input(\"请输入一个数:\")\n",
|
|
|
+ "num = int(num)\n",
|
|
|
+ "if num % 2 == 0:\n",
|
|
|
+ " print(F\"\\033[33;41m{num}是偶函数!\")\n",
|
|
|
+ "else:\n",
|
|
|
+ " print(F\"{num}是奇数!\")\n",
|
|
|
+ " "
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "1b2a3cd6-0065-4d1a-81b5-af43590d19d8",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ " * \n",
|
|
|
+ " *** \n",
|
|
|
+ " ***** \n",
|
|
|
+ " ******* \n",
|
|
|
+ " ********* \n",
|
|
|
+ " *********** \n",
|
|
|
+ " ************* \n",
|
|
|
+ " *************** \n",
|
|
|
+ " ***************** \n",
|
|
|
+ " ******************* \n",
|
|
|
+ " ********************\n",
|
|
|
+ " ****************** \n",
|
|
|
+ " **************** \n",
|
|
|
+ " ************** \n",
|
|
|
+ " ************ \n",
|
|
|
+ " ********** \n",
|
|
|
+ " ******** \n",
|
|
|
+ " ****** \n",
|
|
|
+ " **** \n",
|
|
|
+ " ** \n",
|
|
|
+ " \n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "r = 10\n",
|
|
|
+ "for y in range(2*r+1):\n",
|
|
|
+ " for x in range(2*r+1):\n",
|
|
|
+ " if y>=-x+r and y>=x-r and y<x+r and y<=-x+3*r:\n",
|
|
|
+ " print(\"*\",end=\"\")\n",
|
|
|
+ " else:\n",
|
|
|
+ " print(\" \",end=\"\")\n",
|
|
|
+ " print()"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "847999d4-2ff3-49f5-ba16-804c067d7aa4",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "ename": "",
|
|
|
+ "evalue": "",
|
|
|
+ "output_type": "error",
|
|
|
+ "traceback": [
|
|
|
+ "\u001b[1;31mRunning cells with 'c:\\Program Files\\Python39\\python.exe' requires the ipykernel package.\n",
|
|
|
+ "\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
|
|
|
+ "\u001b[1;31mCommand: '\"c:/Program Files/Python39/python.exe\" -m pip install ipykernel -U --user --force-reinstall'"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "b = True\n",
|
|
|
+ "num = input(\"输入一个被判断的整数\")\n",
|
|
|
+ "num = int(num)\n",
|
|
|
+ "for i in range(2,num):\n",
|
|
|
+ " if num % i ==0:\n",
|
|
|
+ " b = False\n",
|
|
|
+ " break\n",
|
|
|
+ " else:\n",
|
|
|
+ " continue\n",
|
|
|
+ "if b:\n",
|
|
|
+ " print(\"素数\")\n",
|
|
|
+ "else:\n",
|
|
|
+ " print(\"和数\")"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 41,
|
|
|
+ "id": "00b1389b-086d-4980-a98f-d08e7e3aa261",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "[2, 3, 5, 7]\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "a = 100\n",
|
|
|
+ "result = [2]\n",
|
|
|
+ "for num in range(3,a,2):\n",
|
|
|
+ " for i in range(2,num):\n",
|
|
|
+ " if num % i ==0:\n",
|
|
|
+ " b = False\n",
|
|
|
+ " break\n",
|
|
|
+ " else:\n",
|
|
|
+ " continue\n",
|
|
|
+ " if b:\n",
|
|
|
+ " result.append(num)\n",
|
|
|
+ "print(result)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "id": "d0cdbeed-3c84-4f79-bec3-8969ea65dcf7",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": []
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "metadata": {
|
|
|
+ "kernelspec": {
|
|
|
+ "display_name": "Python 3 (ipykernel)",
|
|
|
+ "language": "python",
|
|
|
+ "name": "python3"
|
|
|
+ },
|
|
|
+ "language_info": {
|
|
|
+ "codemirror_mode": {
|
|
|
+ "name": "ipython",
|
|
|
+ "version": 3
|
|
|
+ },
|
|
|
+ "file_extension": ".py",
|
|
|
+ "mimetype": "text/x-python",
|
|
|
+ "name": "python",
|
|
|
+ "nbconvert_exporter": "python",
|
|
|
+ "pygments_lexer": "ipython3",
|
|
|
+ "version": "3.9.13"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "nbformat": 4,
|
|
|
+ "nbformat_minor": 5
|
|
|
+}
|