{ "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