# 教案：第20节 —— math 与 time 模块

---

## 元信息

| 项目 | 内容 |
|------|------|
| **课程编号** | G2_第20节 |
| **GESP等级** | **二级**（GESP Python 二级考点，GESP #35） |
| **适用年龄** | 9-11 岁（编程进阶阶段） |
| **核心知识点** | import math、math.pi/sqrt/ceil/floor、time.sleep、turtle 万花筒 |
| **记忆钩子** | "pi=3.14 sqrt开方 floor向下 ceil向上" |
| **身体锚点** | ① import（打开工具箱） ② floor（蹲下） ③ ceil（踮脚） |

---

## 课程目标

1. **掌握** math 模块的核心函数：pi、sqrt、floor、ceil
2. **理解** 模块导入的三种方式及其区别
3. **使用** time.sleep 控制程序节奏
4. **综合** 运用 math + turtle 创作数学万花筒

---

## 五段式 60 分钟教学流程

---

### 第一段：导入（00:00 - 10:00）—— "Python 的数学工具箱"

#### 教师活动

| 时间 | 活动内容 | 教学方式 |
|------|---------|---------|
| 0-3min | 提问："如果让你用手算圆的周长，你需要什么？" 引出"需要 pi" | 生活化提问 |
| 3-6min | "Python 把数学工具都放在一个箱子里，就是 math 模块。要用就得先 import 打开箱子" | 类比讲解 |
| 6-10min | 演示三种导入方式，重点讲 "import math，用 math. 前缀调用" | 代码演示 |

#### 导入代码

```python
# 方式 A：import math（推荐）
import math
print(math.pi)        # 3.141592653589793
print(math.sqrt(16))  # 4.0

# 方式 B：from math import *（不推荐）
from math import *
print(pi)             # 直接写，不用前缀
# 风险：可能与变量重名

# 方式 C：精确导入（推荐）
from math import pi, sqrt
print(pi, sqrt(100))
```

#### 身体锚点

> **【身体锚点 — 打开工具箱】**
> 两手做打开箱子动作，说："import——打开工具箱！"
> 然后做从箱子里拿出工具的手势："math.pi——拿出 pi！"
> "math.sqrt——拿出平方根计算器！"

---

### 第二段：知识点精讲（10:00 - 30:00）

#### 2.1 math.pi —— 圆周率常量（5min）

```python
import math
print(math.pi)    # 3.141592653589793
```

| 属性 | 说明 |
|------|------|
| 类型 | 常量（不是函数，没有括号） |
| 精度 | 约 15 位小数 |
| 用途 | 圆周长 C=2pr、圆面积 S=pr^2 |

**板书：**
```
p ≈ 3.141592653589793
C = 2 x p x r
S = p x r^2
```

#### 2.2 math.sqrt(x) —— 平方根（5min）

```python
import math
print(math.sqrt(100))    # 10.0
print(math.sqrt(2))      # 1.4142135623730951
print(math.sqrt(9))      # 3.0
```

**要点：**
- 返回值永远是 float（小数）类型
- 参数必须 >= 0，否则报错 ValueError
- 等价于 x ** 0.5，但 sqrt 可读性更好

**应用：勾股定理**
```python
# 直角三角形 a=3, b=4, 求斜边 c
c = math.sqrt(3**2 + 4**2)    # c = 5.0
```

#### 2.3 math.floor(x) —— 向下取整（5min）

```python
import math
print(math.floor(3.9))     # 3
print(math.floor(3.1))     # 3
print(math.floor(-3.1))    # -4  注意！
```

**记忆技巧：** floor = 地板，向地板方向取整（更小）

**floor vs int() 的区别：**
```python
math.floor(-3.1)    # -4  向负无穷
int(-3.1)           # -3  向零取整
```

#### 2.4 math.ceil(x) —— 向上取整（5min）

```python
import math
print(math.ceil(3.1))     # 4
print(math.ceil(3.9))     # 4
print(math.ceil(-3.1))    # -3  注意！
```

**记忆技巧：** ceil = 天花板，向天花板方向取整（更大）

**floor vs ceil 对比表：**

| x | floor(x) | ceil(x) |
|---|---------|---------|
| 3.1 | 3 | 4 |
| 3.9 | 3 | 4 |
| -3.1 | -4 | -3 |
| -3.9 | -4 | -3 |

#### 2.5 time.sleep() —— 让程序暂停一下（3min）

```python
import time

print("开始")
time.sleep(2)        # 暂停 2 秒
print("2 秒后……")

# 应用：倒计时
for i in range(5, 0, -1):
    print(i)
    time.sleep(1)    # 每秒数一个数
print("时间到！")
```

**用途：**
- 控制 turtle 动画速度
- 制作倒计时效果
- 防止程序执行太快看不清

---

### 第三段：演示（30:00 - 40:00）—— "math 实战应用"

#### 演示 1：计算圆的周长

```python
import math

radius = 5
circumference = 2 * math.pi * radius
print(f"半径 = {radius}")
print(f"圆周率 pi = {math.pi}")
print(f"周长 C = 2pir = {circumference:.2f}")
```

#### 演示 2：勾股定理求矩形对角线

```python
import math

width = 3
height = 4
diagonal = math.sqrt(width ** 2 + height ** 2)

print(f"矩形宽 = {width}, 高 = {height}")
print(f"对角线 = sqrt(3^2 + 4^2) = {diagonal}")
```

#### 演示 3：floor/ceil 实际应用 —— 分页计算

```python
import math

total_items = 53
items_per_page = 10
total_pages = math.ceil(total_items / items_per_page)

print(f"共 {total_items} 条，每页 {items_per_page} 条")
print(f"需要 {total_pages} 页")    # 6 页（ceil 向上取整）

page = 3
start = items_per_page * (page - 1) + 1
end = min(items_per_page * page, total_items)
print(f"第 {page} 页：第 {start} ~ {end} 条")
```

#### 演示 4：time.sleep + turtle 制作动画

```python
import turtle
import time

t = turtle.Turtle()
t.speed(1)

# 画正方形，每画一条边停一下
for i in range(4):
    t.forward(100)
    t.right(90)
    time.sleep(0.5)
```

---

### 第四段：实操练习（40:00 - 55:00）

#### 练习 1：math 函数填空（5min）

```python
import math

print("pi =", ____)              # 预期: 3.141592653589793
print("sqrt(100) =", ____(100))  # 预期: 10.0
print("floor(3.9) =", ____(3.9)) # 预期: 3
print("ceil(3.1) =", ____(3.1))  # 预期: 4
```

**答案：** math.pi, math.sqrt, math.floor, math.ceil

#### 练习 2：计算圆形周长（5min）

```python
import turtle
import math

radius = 50
turtle.circle(radius)
circumference = 2 * math.pi * radius
print(f"半径为 {radius} 的圆，周长为 {circumference:.2f}")
turtle.done()
```

#### 练习 3：应用题——花坛围栏（5min）

```python
import math

radius = 2.5
circumference = 2 * math.pi * radius
screws = math.ceil(circumference * 8)

print(f"花坛半径: {radius} 米")
print(f"围栏长度: {circumference:.2f} 米")
print(f"所需螺丝: {screws} 颗")
```

#### 挑战拓展：math + time 万花筒（5min）

```python
import turtle
import math
import time

t = turtle.Turtle()
t.speed(0)
turtle.bgcolor("black")

for angle in range(0, 360, 15):
    rad = math.radians(angle)
    x = 150 * math.cos(rad)
    y = 150 * math.sin(rad)
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.dot(10, "red")
    time.sleep(0.1)

turtle.done()
```

---

### 第五段：小测（55:00 - 60:00）

#### 题目 1（选择）
math.sqrt(100) 的结果是？
A. 10
B. 10.0
C. 100
D. 50

**答案：B**（sqrt 永远返回 float 类型）

#### 题目 2（选择）
math.floor(3.9) 的结果是？
A. 3
B. 4
C. 3.0
D. 4.0

**答案：A**

#### 题目 3（选择）
math.ceil(3.1) 的结果是？
A. 3
B. 4
C. 3.0
D. 4.0

**答案：B**

#### 题目 4（填空）
- math.sqrt(100) = ____
- math.floor(-3.1) = ____
- math.pi 的值约等于 ____（保留 5 位小数）

**答案：** 10.0, -4, 3.14159

#### 题目 5（判断）
time.sleep(2) 让程序暂停 2 毫秒。

**答案：** 错（是 2 秒，不是毫秒）

---

## 板书设计

```
+-------------------------------------------------------+
|       第20节  math 与 time 模块                        |
+-------------------------------------------------------+

  导入模块的三种方式：
  import math                  (推荐，用 math. 前缀)
  from math import *           (不推荐，有重名风险)
  from math import pi, sqrt    (精确导入)

  math 工具箱：
  . math.pi     = 3.14159  （圆周率）
  . math.sqrt(x) = sqrt(x) （平方根，返回 float）
  . math.floor(x)           （向下取整，向地板）
  . math.ceil(x)            （向上取整，向天花板）

  time.sleep(秒)  让程序暂停

  记忆钩子：
  "pi=3.14 sqrt开方 floor向下 ceil向上"
---

## 课后延伸

| 项目 | 内容 |
|------|------|
| 课后练习 | 课后练习_第20节.md |
| 预习内容 | 第20节 random 模块 |
| 拓展挑战 | 用 math 和 turtle 画一个螺旋线（半径递增的圆） |
| 家长沟通 | 今天学习了 Python 的 math 和 time 模块，孩子会用数学函数解决几何问题 |

---

## 教学反思

| 维度 | 记录 |
|------|------|
| 学生掌握率 | 预计 75% 学生能独立使用 math 函数 |
| 常见困惑 | sqrt 返回 float 而非 int，floor/ceil 负数的取整方向 |
| 改进方向 | 增加 floor/ceil 的负数案例练习 |
| 备注 | 万花筒项目可作为课后兴趣拓展，不在课内强求完成 |
```
