{ "cells": [ { "cell_type": "markdown", "id": "f45637ae-7baf-4bb0-9b1a-2310e4ae64eb", "metadata": {}, "source": [ "# 零基础编程课\n", "## 第 1 课" ] }, { "cell_type": "markdown", "id": "d3193bb2-d5bb-4d7e-9ae1-441d4dc90e4e", "metadata": {}, "source": [ "#### 观看以下小视频:0 编程软件预备和介绍" ] }, { "cell_type": "code", "execution_count": 3, "id": "af4e7972-ce1e-47f2-a54c-4b4cfae292e9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 如果小视频没有显示,请运行以下的代码\n", "from IPython.display import IFrame\n", "IFrame('https://player.bilibili.com/player.html?aid=522445062&bvid=BV1ZM411a7TL&cid=954790812&page=1',width=500,height=400)" ] }, { "cell_type": "markdown", "id": "9af96306-9184-4dd5-8e91-c42ad0c5412b", "metadata": {}, "source": [ "#### 观看以下小视频:1 关于编程1 什么是编程" ] }, { "cell_type": "code", "execution_count": 4, "id": "fbf137dc-d216-46ae-8e2c-d2b6c594adb9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 如果小视频没有显示,请运行以下的代码\n", "from IPython.display import IFrame\n", "IFrame('https://player.bilibili.com/player.html?aid=729764083&bvid=BV11S4y1W71M&cid=811919156&page=1',width=500,height=400)" ] }, { "cell_type": "markdown", "id": "e3d4bd32-9c6a-47bc-91cd-53ad6618accc", "metadata": {}, "source": [ "#### 观看以下小视频:1 关于编程2 编程目的1" ] }, { "cell_type": "code", "execution_count": 5, "id": "6c5a2bb2-fe9b-4419-bbed-39e802a5835a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 如果小视频没有显示,请运行以下的代码\n", "from IPython.display import IFrame\n", "IFrame('https://player.bilibili.com/player.html?aid=729859397&bvid=BV1mD4y1z7vE&cid=811920805&page=1',width=500,height=400)" ] }, { "cell_type": "markdown", "id": "58e284fa-82e3-42b8-8cf4-2e3652b5704f", "metadata": {}, "source": [ "#### 观看以下小视频:1 关于编程3 编程目的2" ] }, { "cell_type": "code", "execution_count": null, "id": "06bdce92-9f36-4c36-b3b4-59f4f2b6d473", "metadata": {}, "outputs": [], "source": [ "# 如果小视频没有显示,请运行以下的代码\n", "from IPython.display import IFrame\n", "IFrame('https:////player.bilibili.com/player.html?aid=429791267&bvid=BV1eG41147sn&cid=811921633&page=1',width=500,height=400)" ] }, { "cell_type": "markdown", "id": "da1dc6c3-5f20-4b5b-ae03-fbdffcf40af4", "metadata": {}, "source": [ "## 练习册1:运行简单程序\n", "第一个入门编程代码便是显示 **Hello, World!**,以下例子1的代码的目的是显示 **Hello, World!**
\n", "### 例子 1\n", "运行以下的代码。" ] }, { "cell_type": "code", "execution_count": null, "id": "9482c73c-241e-4862-8fce-6294a99f26c9", "metadata": {}, "outputs": [], "source": [ "# 例子 1 显示Hello, World!\n", "print(\"Hello, World!\")" ] }, { "cell_type": "markdown", "id": "fdfb8dd4-22ba-4cc6-8662-44844fc5a89d", "metadata": {}, "source": [ "### 练习 1\n", "修改下面的程序,用你的名字替换World,然后运行程序。
\n", "举例:如果你的名字是**康晓明**,程序运行后应该显示**Hello, 康晓明!**" ] }, { "cell_type": "code", "execution_count": null, "id": "f7629e66-4c0b-4e6d-ad9c-9dddf7289ee0", "metadata": {}, "outputs": [], "source": [ "# 练习 1\n", "print(\"Hello, World!\")" ] }, { "cell_type": "markdown", "id": "324e552b-f246-4360-8c19-f4dfe236a254", "metadata": {}, "source": [ "### 变量与值\n", "我们可以用变量代表一个值
\n", "### 例子 2\n", "在下面例子2的代码里,变量 **t** 被赋予了 Hello, World! 这个值,然后显示这个变量。
\n", "运行下面的程序。" ] }, { "cell_type": "code", "execution_count": null, "id": "bb8d3b04-aa17-4df3-873c-34f6966c55df", "metadata": {}, "outputs": [], "source": [ "# 例子 2 \n", "t = \"Hello, World!\" #给变量赋值\n", "print(t) #显示变量" ] }, { "cell_type": "markdown", "id": "76f8622a-6f57-4af4-96eb-fe6556ec130d", "metadata": {}, "source": [ "我们看到运行的结果是和例子1是一样的。这里变量 **t** 代表了一个值,就是**Hello, World!**" ] }, { "cell_type": "markdown", "id": "8a06b37a-ad4d-4a30-b27b-27f7fe41fac1", "metadata": {}, "source": [ "上面的例子里,我们给变量赋的值是一串文字或字符,这种数据格式在Python编程里叫**字符串**。一个字符串里可以包含英文,中文,标点符号,数字等等,但开始和结束要用单引号或双引号标明。
" ] }, { "cell_type": "markdown", "id": "33f8e7ab-1d18-44c1-92c6-f95aef034a0e", "metadata": {}, "source": [ "### 练习 2\n", "完成下面的代码,把你的名字赋值给变量 t,然后显示 t
\n", "举例:如果你的名字是**康晓明**,程序运行后应该显示**康晓明**" ] }, { "cell_type": "code", "execution_count": null, "id": "13046ba3-e2e0-4d7c-91e7-9777555019ee", "metadata": {}, "outputs": [], "source": [ "# 练习 2 \n", "t = ____\n", "print(t) " ] }, { "cell_type": "markdown", "id": "77759080-d9b0-4cdb-8f50-65ef7816411f", "metadata": { "tags": [] }, "source": [ "### 例子 3\n", "在下面例子3的代码里,变量 **a** 被赋予了 5 这个值,然后显示这个变量。
\n", "运行下面的程序。" ] }, { "cell_type": "code", "execution_count": null, "id": "c8d03ccd-eab3-4b74-8ca8-34bfb569eecc", "metadata": {}, "outputs": [], "source": [ "# 例子 3 \n", "a = 5 #给变量赋值\n", "print(a) #显示变量" ] }, { "cell_type": "markdown", "id": "fd64668b-3055-4b93-83e2-7a4f9c2b6884", "metadata": {}, "source": [ "### 练习 3\n", "修改下面的程序,用你自己的年龄替换原来的值(5),然后运行程序。
\n", "举例:如果你的年龄是**20**,程序运行后应该显示**20**" ] }, { "cell_type": "code", "execution_count": null, "id": "fc9e2872-0837-4241-b762-9365d58bbd4a", "metadata": {}, "outputs": [], "source": [ "# 练习 3 \n", "age = 5 \n", "print(age) " ] }, { "cell_type": "markdown", "id": "78b1b4b4-4f80-4206-abe4-2085bd446bc6", "metadata": {}, "source": [ "我们可以把不同的内容一起显示出来。 \n", "运行以下的例子4,理解代码的意思。" ] }, { "cell_type": "code", "execution_count": null, "id": "8c890151-1aa1-48d9-843a-050aac9392fd", "metadata": {}, "outputs": [], "source": [ "# 例子 4\n", "t = \"Henry\" \n", "print(\"名字\",t) " ] }, { "cell_type": "markdown", "id": "c74f393a-267f-46bb-96f9-0ac9e2884442", "metadata": {}, "source": [ "要显示的有两个内容,**名字** 和 **t**,逗号把两者分开,print会按照顺序一一显示。 \n", "运行下面的例子5,理解代码的意思。" ] }, { "cell_type": "code", "execution_count": null, "id": "534cb186-5f11-4b1e-ab59-e544cf81dc16", "metadata": {}, "outputs": [], "source": [ "# 例子 5 \n", "l = \"名字\"\n", "t = \"Henry\" \n", "print(l, t) " ] }, { "cell_type": "markdown", "id": "cec9e9cd-9811-40be-a482-a118c3a0df0f", "metadata": {}, "source": [ "上面的例子里,显示的结果是一样的,只不过是用变量代替了原来的字符串。" ] }, { "cell_type": "markdown", "id": "eb673ce7-9b79-4c47-87e4-7209c1722761", "metadata": {}, "source": [ "### 练习 4\n", "完成下面的代码,显示***我的年龄是15岁***。
\n", "要求:你的代码里面一定要用到变量**a**" ] }, { "cell_type": "code", "execution_count": null, "id": "fb7ec8e7-53ec-450a-be78-db6a06001a42", "metadata": {}, "outputs": [], "source": [ "# 练习 4 \n", "a = 15\n", "####### 你的代码写在下面 #########\n", "print(____)" ] } ], "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 }