删去不需要的代码

This commit is contained in:
2025-06-15 15:06:46 +08:00
parent 6aed724db5
commit b5fe80000e
21 changed files with 5 additions and 567 deletions

View File

@@ -1,49 +0,0 @@
## 第一: print 后面跟着英文括号,不要写等号!!!
### 下面是错误的:
```py
print=("China")
```
## 第二: 所有的符号都是英文的
### 下面是错误的:
```py
print"China"
print(“China”)
```
## 第三:下面的写法是等价的
### 第一种:
```py
a="China"
print(a)
```
### 第二种:
```py
print("China")
```
## 第四输出有几行就需要几个print()
### 输出三行你好:
```py
print("你好")
print("你好")
print("你好")
```
## 第五:每行输出多个
```py
print("程旭", "赵铖洋", "於锦诚", "叶小斌", "洋芋头", "池涛涛")
```
在右边的代码中找找茬吧Let's GO

View File

@@ -1,7 +0,0 @@
print黄岩一职
print(黄岩一职)
print=黄岩一职
Print(a)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

View File

@@ -1,50 +0,0 @@
![会赢的](./image.png)
## input() 的简单用法
这是书上没有讲的内容
`input()` 函数会等待用户输入,等用户输入结束,按下回车键后,得到用户输入的内容,数据类型是**文字**类型
比如:
```py
# 变量a得到的就是用户输入的内容
a = input("请输入的你的姓名:")
# 使用加号连接两段文字
print("你的姓名是:"+a)
```
在 Thonny 上演示注意input() 函数括号中的文字是输入时候的提示语。
## 在【判题狗】中,所有的输入都不要写提示语
## 重要提醒:用户输入的内容是不会出现在代码中的
因为你无法预测用户会输入什么
## 当遇到用户输入的是一个整数或一个小数
因为 `input()` 得到的都是文字类型,所以看上去输入了一个数字,其实文字,所以我们需要进行类型转换
### 输入一个整数,比如输入 10
```py
# 用 int() 包裹 input(),这样得到的 a 就是一个整数类型
a=int(input())
print(a+10)
```
输入10
输出20
### 输入一个小数,比如输入 3.14
```py
# 用 float() 包裹 input(),这样得到的 a 就是一个小数类型
a=float(input())
print(a-3)
```
输入3.14
输出0.14

View File

@@ -1,51 +0,0 @@
遇到以下情况:
## 输入的文字,用空格隔开。比如:你好 世界
你输入的`"你好 世界"`是一句话,但是你需要得到 `"你好"``"世界"`并分别赋值给两个变量a和b。
你需要这样写:
```py
a,b=input().split()
```
如果是三个用空格隔开,比如:小明 小华 小王
```py
a,b,c=input().split()
```
`a` 代表 小明,`b` 代表 小华,`c` 代表 小王
## 输入两个整数用空格隔开。比如10 20
写法如下:
```py
n=input().split()
a=int(n[0])
b=int(n[1])
```
如果是三个整数,以此类推:
```py
n=input().split()
a=int(n[0])
b=int(n[1])
c=int(n[2])
```
## 要是小数。比如2.33 5.18
写法如下:
```py
n=input().split()
a=float(n[0])
b=float(n[1])
```

View File

@@ -1,22 +0,0 @@
# 两个文字用空格隔开比如C语言 Python
a,b=input().split()
# 三个整数用空格隔开比如1 3 5
n=input().split()
x=int(n[0])
y=int(n[1])
z=int(n[2])
# 四个小数用空格隔开比如1.2 1.4 5.3 0.3
n=input().split()
a=float(n[0])
b=float(n[1])
c=float(n[2])
d=float(n[3])
# 使用 map 的简化写法
# 五个整数用空格隔开
a,b,c,d,e=map(int, input().split())
# 六个小数用空格隔开
a,b,c,d,e,f=map(float, input().split())

View File

@@ -1,74 +0,0 @@
经常会有输出要保留N位小数的情况比如[1046 圆的面积](https://oj.xuyue.cc/problem/1046) 这道题需要保留4位小数
## "%.2f" % 方法
使用方法如下:
```py
a=1.23456
print("%.4f" % a)
print("%.3f" % a)
print("%.2f" % a)
```
得到的结果
```py
1.2346
1.235
1.23
```
这个方法**会进行四舍五入**
### 注意:"%.2f" % 后面只能跟着一个变量或运算结果,不能跟着计算表达式
下面代码运行会**报错**
```py
a=10
b=3
print("%.2f" % a/b) # 这里是错误的❌
```
可以改成:
```py
a=10
b=3
c=a/b
print("%.2f" % c) # 这样是正确的✔
```
或者,把计算表达式用括号包起来
```py
a=10
b=3
print("%.2f" % (a/b)) # 这样是正确的✔
```
## format() 函数
使用方法如下:
```py
a=1.23456
print(format(a, ".4f"))
print(format(a, ".3f"))
print(format(a, ".2f"))
```
**不要忘记小数点**
得到的结果
```py
1.2346
1.235
1.23
```
这个方法**会进行四舍五入**

View File

@@ -1,9 +0,0 @@
a=1.23456
print("%.4f" % a)
print("%.3f" % a)
print("%.2f" % a)
print(format(a, ".4f"))
print(format(a, ".3f"))
print(format(a, ".2f"))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -1,31 +0,0 @@
你会经常遇到变量和文字连接的场景:如果这个变量是文字类型,那还比较简单,直接使用➕连接。但是这个变量是**数字**,就麻烦了,比如:
```py
a=1
print("计算机"+a+"班")
```
这样会报错
![报错](./image.png)
报错的信息表示:文字不能和数字相连接,必须先把数字转成文字。
遇到这种变量和文字拼接的题目,使用格式化文字比较容易解决,同样上面的代码可以改成:
```py
a=1
print(f"计算机{a}班")
```
得到结果计算机1班
记住格式:**引号前面写个f然后变量用{}包裹**
并且,{}里面可以写表达式,可以得到运算的结果:
```py
print(f"1+1={1+1}")
```
得到结果1+1=2

View File

@@ -1,8 +0,0 @@
a=1
print(f"计算机{a}")
# 四则运算
print(f"1 + 1 = {1+1}")
print(f"1 - 1 = {1-1}")
print(f"1 * 1 = {1*1}")
print(f"1 / 1 = {1//1}")

View File

@@ -1,13 +0,0 @@
> 全都怪我
> 不该沉默时沉默
> 该勇敢时软弱
> 如果不是我
> 误会自己洒脱
> 让我们难过
> 可当初的你
> 和现在的我
> 假如重来过 ——《可惜没如果》
你的爱情可惜没如果但是Python不可惜因为Python有if不愧是年度最佳烂梗
## 学好if就一句话注意缩进

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

View File

@@ -1,26 +0,0 @@
自测猫有个功能是可以看见循环过程的,叫做【可视化调试】,打开 [自测猫](https://code.xuyue.cc)
复制以下代码到自测猫
```py
print("我要开始循环啦!")
i=0
while i<10:
print("我在循环内", i)
i=i+1
print("结束循环啦!")
```
点击红色的【调试】按钮,弹出调试框:
![](./image1.png)
绿色箭头表示当前正在执行,红色箭头表示下一步要执行。点击下一步,开始调试。
![](./gif1.gif)
当然你也可以来回拖动进步条,这样代码就会跟着你的想法,想走到哪一步就走到哪一步。
![](./gif2.gif)
右侧可以看到当前变量的值。

View File

@@ -1,12 +0,0 @@
import http from "utils/http"
export async function list() {
const res = await http.get("tutorials")
return res.data
}
export async function get(id: string) {
const res = await http.get(`tutorial/${id}`)
return res.data
}

View File

@@ -1,142 +0,0 @@
<script setup lang="ts">
import { Icon } from "@iconify/vue"
import { useLearnStore } from "./store"
const CodeEditor = defineAsyncComponent(
() => import("~/shared/components/CodeEditor.vue"),
)
const route = useRoute()
const learnStore = useLearnStore()
const content = shallowRef()
async function init() {
content.value = defineAsyncComponent(
() => import(`./${learnStore.dirname}/index.md`),
)
learnStore.currentTitle = learnStore.menu[learnStore.current - 1]
.label as string
try {
const raw = await import(`./${learnStore.dirname}/main.py?raw`)
learnStore.code = raw.default
learnStore.showCode = true
} catch (err) {
learnStore.code = ""
learnStore.showCode = false
}
}
watch(
() => route.params.step,
async () => {
if (route.name !== "learn") return
init()
},
{ immediate: true },
)
</script>
<template>
<n-grid :cols="2" :x-gap="24">
<n-gi :span="1">
<n-flex vertical>
<n-flex align="center">
<n-button
text
:disabled="learnStore.current == 1"
@click="learnStore.prev"
>
<Icon :width="30" icon="pepicons-pencil:arrow-left"></Icon>
</n-button>
<n-dropdown size="large" :options="learnStore.menu" trigger="click">
<n-button tertiary style="flex: 1" size="large">
<n-flex align="center">
<span style="font-weight: bold">
{{ learnStore.currentTitle }}
</span>
<Icon :width="24" icon="proicons:chevron-down"></Icon>
</n-flex>
</n-button>
</n-dropdown>
<n-button
text
:disabled="learnStore.current == learnStore.total"
@click="learnStore.next"
>
<Icon :width="30" icon="pepicons-pencil:arrow-right"></Icon>
</n-button>
</n-flex>
<n-flex vertical size="large">
<Component :is="content"></Component>
<n-flex justify="space-between">
<div style="flex: 1">
<n-button
block
style="height: 60px"
v-if="learnStore.current !== 1"
@click="learnStore.prev"
>
上一课时
</n-button>
</div>
<div style="flex: 1">
<n-button
block
style="height: 60px"
v-if="learnStore.current !== learnStore.total"
@click="learnStore.next"
>
下一课时
</n-button>
</div>
</n-flex>
</n-flex>
</n-flex>
</n-gi>
<n-gi :span="1">
<n-flex vertical>
<CodeEditor
v-show="learnStore.showCode"
language="Python3"
v-model="learnStore.code"
/>
</n-flex>
</n-gi>
</n-grid>
</template>
<style>
html.dark .shiki,
html.dark .shiki span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
}
.markdown-body code {
font-size: 20px;
font-family: "Monaco";
}
.markdown-body h2 {
font-size: 24px;
}
.markdown-body h3 {
font-size: 22px;
}
.markdown-body p {
font-size: 18px;
}
.markdown-body img {
max-width: 100%;
}
.markdown-body a {
color: #4493f8;
text-decoration: none;
}
</style>

View File

@@ -1,7 +0,0 @@
重生之我写Python
会赢的!
不是,你怎么说话带空格啊?
你这身高绝对没有1米76
优美的Python语言之f**k-string
全都怪我,不该沉默时沉默
可以看到的循环

View File

@@ -1,65 +0,0 @@
import sidebar from "./menu.md?raw"
export const useLearnStore = defineStore("learn", () => {
const route = useRoute()
const router = useRouter()
const code = ref("")
const input = ref("")
const output = ref("黄岩一职")
const showCode = ref(true)
const currentTitle = ref("")
const current = computed(() => {
if (!route.params.step || !route.params.step.length) return 1
else {
return parseInt(route.params.step[0])
}
})
const dirname = computed(() => current.value.toString().padStart(2, "0"))
const menu: DropdownOption[] = sidebar
.split("\n")
.filter((title) => !!title)
.map((title: string, index) => {
const dirname = (index + 1).toString().padStart(2, "0")
const prefix = `${index + 1} 课:`
return {
key: dirname,
label: prefix + title,
props: {
onClick: () => {
router.push(`/learn/${dirname}`)
currentTitle.value = prefix + title
},
},
}
})
function next() {
if (current.value === menu.length) return
const dest = (current.value + 1).toString().padStart(2, "0")
router.push("/learn/" + dest)
}
function prev() {
if (current.value === 1) return
const dest = (current.value - 1).toString().padStart(2, "0")
router.push("/learn/" + dest)
}
return {
code,
input,
output,
showCode,
currentTitle,
total: menu.length,
current,
dirname,
menu,
next,
prev,
}
})

View File

@@ -142,4 +142,8 @@ watch(
) )
</script> </script>
<style></style> <style>
.md-editor-preview .md-editor-code .md-editor-code-head {
z-index: 100;
}
</style>