diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 717766f..514901d 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -45,6 +45,10 @@ export default defineConfig({ link: "/basic/tips/error-message/index.md", }, { text: "使用 AI", link: "/basic/tips/chatgpt/index.md" }, + { + text: "可视化执行流程", + link: "/basic/tips/pythontutor/index.md", + }, ], }, { diff --git a/basic/tips/cheatsheet/index.md b/basic/tips/cheatsheet/index.md index 7d70cbf..40bbe90 100644 --- a/basic/tips/cheatsheet/index.md +++ b/basic/tips/cheatsheet/index.md @@ -3,24 +3,44 @@ > 抄抄抄 1. 输出保留两位小数 + ```py a = 10.2980 print("%.2f" % a) ``` + 2. 输入一个整数 + +比如输入128 + ```py a=int(input()) ``` +得到变量a就是整数128 + 3. 输入两个整数,用空格隔开 + +比如输入 10 20 + ```py n=input().split() a=int(n[0]) b=int(n[1]) ``` -4. 输入文字,用空格隔开(这里用三个文字做例子,比如:iPhone Huawei Xiaomi) +得到变量a就是整数10,变量b就是整数20 + +4. 输入文字,用空格隔开 + +比如输入 iPhone Huawei Xiaomi + ```py -a,b,c=input().split() +n=input().split() +a=n[0] +b=n[1] +c=n[2] ``` + +得到变量a就是iPhone,变量b就是Huawei,变量c就是Xiaomi diff --git a/basic/tips/pythontutor/PixPin_2024-12-19_11-19-48.gif b/basic/tips/pythontutor/PixPin_2024-12-19_11-19-48.gif new file mode 100644 index 0000000..fb3f37c Binary files /dev/null and b/basic/tips/pythontutor/PixPin_2024-12-19_11-19-48.gif differ diff --git a/basic/tips/pythontutor/PixPin_2024-12-19_11-22-54.gif b/basic/tips/pythontutor/PixPin_2024-12-19_11-22-54.gif new file mode 100644 index 0000000..0faee7c Binary files /dev/null and b/basic/tips/pythontutor/PixPin_2024-12-19_11-22-54.gif differ diff --git a/basic/tips/pythontutor/PixPin_2024-12-19_11-26-35.gif b/basic/tips/pythontutor/PixPin_2024-12-19_11-26-35.gif new file mode 100644 index 0000000..ad3485a Binary files /dev/null and b/basic/tips/pythontutor/PixPin_2024-12-19_11-26-35.gif differ diff --git a/basic/tips/pythontutor/image-1.png b/basic/tips/pythontutor/image-1.png new file mode 100644 index 0000000..29cffad Binary files /dev/null and b/basic/tips/pythontutor/image-1.png differ diff --git a/basic/tips/pythontutor/image-10.png b/basic/tips/pythontutor/image-10.png new file mode 100644 index 0000000..95fbc79 Binary files /dev/null and b/basic/tips/pythontutor/image-10.png differ diff --git a/basic/tips/pythontutor/image-2.png b/basic/tips/pythontutor/image-2.png new file mode 100644 index 0000000..4fb5d80 Binary files /dev/null and b/basic/tips/pythontutor/image-2.png differ diff --git a/basic/tips/pythontutor/image-3.png b/basic/tips/pythontutor/image-3.png new file mode 100644 index 0000000..eca38bd Binary files /dev/null and b/basic/tips/pythontutor/image-3.png differ diff --git a/basic/tips/pythontutor/image-4.png b/basic/tips/pythontutor/image-4.png new file mode 100644 index 0000000..394f4a4 Binary files /dev/null and b/basic/tips/pythontutor/image-4.png differ diff --git a/basic/tips/pythontutor/image-5.png b/basic/tips/pythontutor/image-5.png new file mode 100644 index 0000000..5a63e96 Binary files /dev/null and b/basic/tips/pythontutor/image-5.png differ diff --git a/basic/tips/pythontutor/image-6.png b/basic/tips/pythontutor/image-6.png new file mode 100644 index 0000000..53e07e5 Binary files /dev/null and b/basic/tips/pythontutor/image-6.png differ diff --git a/basic/tips/pythontutor/image-7.png b/basic/tips/pythontutor/image-7.png new file mode 100644 index 0000000..738c55b Binary files /dev/null and b/basic/tips/pythontutor/image-7.png differ diff --git a/basic/tips/pythontutor/image-8.png b/basic/tips/pythontutor/image-8.png new file mode 100644 index 0000000..3161787 Binary files /dev/null and b/basic/tips/pythontutor/image-8.png differ diff --git a/basic/tips/pythontutor/image-9.png b/basic/tips/pythontutor/image-9.png new file mode 100644 index 0000000..590d796 Binary files /dev/null and b/basic/tips/pythontutor/image-9.png differ diff --git a/basic/tips/pythontutor/image.png b/basic/tips/pythontutor/image.png new file mode 100644 index 0000000..0962ce0 Binary files /dev/null and b/basic/tips/pythontutor/image.png differ diff --git a/basic/tips/pythontutor/index.md b/basic/tips/pythontutor/index.md new file mode 100644 index 0000000..3d752cc --- /dev/null +++ b/basic/tips/pythontutor/index.md @@ -0,0 +1,81 @@ +# 使用 [pythontutor.com](https://pythontutor.com/) 可视化的执行流程 + +![0](image.png) + +由于网站都是英文的,所以接下来我会一步步的截图,请按照顺序执行 + +## 1. 选择编程语言 + +![1](image-1.png) + +## 2. 在输入框中粘贴代码 + + +![2](image-2.png) + +```py +n=1 +i=0 +while i<5: + i=i+1 + n=n*2 + print(n) +``` + +## 3. 点击【可视化执行】按钮 + +![5](image-5.png) + +## 4. 进入调试页面 + +![4](image-4.png) + +① 绿色箭头表示【当前正在】执行的语句 + +② 红色箭头表示【接下来要】执行的语句 + +③ 输出结果 + +④ 显示变量的值 + +## 5. 基础调试 + +![3](image-3.png) + +5.1 不断点击 ①【Next 下一步】按钮 + +5.2 代码左侧 ② 出现绿色和红色箭头,指向【当前】和【接下来】的执行语句。 + +5.3 右侧 ③ 实时展示变量的值 + +**注意观察箭头的走向和变量值的变化** + +![1](PixPin_2024-12-19_11-19-48.gif) + +## 6. 拖动进度条 * + +可以拖动进度条反复查看,或者点击【First】跳到第一步,【Last】直接跳到最后一步 + +![2](PixPin_2024-12-19_11-22-54.gif) + +## 7. 更改代码再次调试 + +点击【Edit this code】按钮可以修改代码 + +![3](PixPin_2024-12-19_11-26-35.gif) + +**可以更改 i 的初始值 i=?,条件符号,条件值,计数器 i=i+? 等** + +![6](image-6.png) + +比如: + +![7](image-7.png) + +![8](image-8.png) + +![9](image-9.png) + +遇到弹框,直接点按钮 + +![10](image-10.png) diff --git a/package-lock.json b/package-lock.json index e71ff23..a5ca536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,12 +11,12 @@ "dependencies": { "@codemirror/lang-cpp": "^6.0.2", "@codemirror/lang-python": "^6.1.6", - "axios": "^1.7.7", + "axios": "^1.7.9", "codemirror": "^6.0.1", - "vue-codemirror6": "~1.3.4" + "vue-codemirror6": "~1.3.8" }, "devDependencies": { - "prettier": "^3.3.3", + "prettier": "^3.4.2", "vitepress": "1.5.0" } }, @@ -472,13 +472,13 @@ } }, "node_modules/@codemirror/lint": { - "version": "6.8.2", - "resolved": "https://registry.npmmirror.com/@codemirror/lint/-/lint-6.8.2.tgz", - "integrity": "sha512-PDFG5DjHxSEjOXk9TQYYVjZDqlZTFaDBfhQixHnQOEVDDNHUbEh/hstAjcQJaA6FQdZTD1hquXTK0rVBLADR1g==", + "version": "6.8.4", + "resolved": "https://registry.npmmirror.com/@codemirror/lint/-/lint-6.8.4.tgz", + "integrity": "sha512-u4q7PnZlJUojeRe8FJa/njJcMctISGgPQ4PnWsd9268R4ZTtU+tfFYmwkBvgcrK2+QQ8tYFVALVb5fVJykKc5A==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.0.0", - "@codemirror/view": "^6.0.0", + "@codemirror/view": "^6.35.0", "crelt": "^1.0.5" } }, @@ -493,18 +493,21 @@ } }, "node_modules/@codemirror/state": { - "version": "6.4.1", - "resolved": "https://registry.npmmirror.com/@codemirror/state/-/state-6.4.1.tgz", - "integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==", - "license": "MIT" - }, - "node_modules/@codemirror/view": { - "version": "6.34.2", - "resolved": "https://registry.npmmirror.com/@codemirror/view/-/view-6.34.2.tgz", - "integrity": "sha512-d6n0WFvL970A9Z+l9N2dO+Hk9ev4hDYQzIx+B9tCyBP0W5wPEszi1rhuyFesNSkLZzXbQE5FPH7F/z/TMJfoPA==", + "version": "6.5.0", + "resolved": "https://registry.npmmirror.com/@codemirror/state/-/state-6.5.0.tgz", + "integrity": "sha512-MwBHVK60IiIHDcoMet78lxt6iw5gJOGSbNbOIVBHWVXIH4/Nq1+GQgLLGgI1KlnN86WDXsPudVaqYHKBIx7Eyw==", "license": "MIT", "dependencies": { - "@codemirror/state": "^6.4.0", + "@marijn/find-cluster-break": "^1.0.0" + } + }, + "node_modules/@codemirror/view": { + "version": "6.36.0", + "resolved": "https://registry.npmmirror.com/@codemirror/view/-/view-6.36.0.tgz", + "integrity": "sha512-aMePDnkNNKE8dSOo1w689xYa3dijREbRajiRcgjSGc2TWN7MTdE+9pm5fxwdz0C4D9Di1VZomrn2M+xDe7tTVg==", + "license": "MIT", + "dependencies": { + "@codemirror/state": "^6.5.0", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } @@ -1013,6 +1016,12 @@ "@lezer/lr": "^1.0.0" } }, + "node_modules/@marijn/find-cluster-break": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz", + "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==", + "license": "MIT" + }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.24.0", "resolved": "https://registry.npmmirror.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.0.tgz", @@ -1705,9 +1714,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmmirror.com/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "version": "1.7.9", + "resolved": "https://registry.npmmirror.com/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", @@ -2277,9 +2286,9 @@ } }, "node_modules/prettier": { - "version": "3.3.3", - "resolved": "https://registry.npmmirror.com/prettier/-/prettier-3.3.3.tgz", - "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "version": "3.4.2", + "resolved": "https://registry.npmmirror.com/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", "dev": true, "license": "MIT", "bin": { @@ -2699,32 +2708,27 @@ } }, "node_modules/vue-codemirror6": { - "version": "1.3.7", - "resolved": "https://registry.npmmirror.com/vue-codemirror6/-/vue-codemirror6-1.3.7.tgz", - "integrity": "sha512-DG2LA5Ps2K8Ot1jlDeaRy28AhI9TKtcbRasT3WMooLxaWfHQcSKtbeANFqRSdECQjXiDVVYNTUte4Y7mR4XtEg==", + "version": "1.3.8", + "resolved": "https://registry.npmmirror.com/vue-codemirror6/-/vue-codemirror6-1.3.8.tgz", + "integrity": "sha512-pCOzKzBBSFKi/SjUg+XGranV1vt+8S22z56BES/OeZtmyuj2M0CE0aczYS8qbTWNnKcuJcI5FRDHzVXy2v2Htg==", "license": "MIT", "dependencies": { "@codemirror/commands": "^6.7.1", "@codemirror/language": "^6.10.3", - "@codemirror/lint": "^6.8.2", + "@codemirror/lint": "^6.8.3", "@codemirror/state": "^6.4.1", - "@codemirror/view": "^6.34.2", + "@codemirror/view": "^6.35.0", "codemirror": "^6.0.1", "style-mod": "^4.1.2", - "vue-codemirror6": "file:", "vue-demi": "latest" }, "engines": { - "pnpm": ">=9.12.3" + "pnpm": ">=9.14.2" }, "peerDependencies": { "vue": "^2.7.14 || ^3.4" } }, - "node_modules/vue-codemirror6/node_modules/vue-codemirror6": { - "resolved": "node_modules/vue-codemirror6", - "link": true - }, "node_modules/vue-demi": { "version": "0.14.10", "resolved": "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.14.10.tgz", diff --git a/package.json b/package.json index 92cec86..d5f9af7 100644 --- a/package.json +++ b/package.json @@ -12,14 +12,14 @@ "author": "", "license": "ISC", "devDependencies": { - "prettier": "^3.3.3", + "prettier": "^3.4.2", "vitepress": "1.5.0" }, "dependencies": { "@codemirror/lang-cpp": "^6.0.2", "@codemirror/lang-python": "^6.1.6", - "axios": "^1.7.7", + "axios": "^1.7.9", "codemirror": "^6.0.1", - "vue-codemirror6": "~1.3.4" + "vue-codemirror6": "~1.3.8" } }