# G2-15 课后练习 —— 列表入门
> **GESP等级：二级 | 考级考点：GESP Python 二级**

**姓名：__________  日期：__________**

---

> 学了用方括号 `[]` 创建列表，用索引取值，用 for 循环遍历。
> 
> 记忆钩子：
> - **"列表 = 一排贴编号盒子，编号从0开始"**
> - **"方盒子用方括号 []"**
> - **"正索引 0 1 2 3...，负索引 -1最后一个 -2倒数第二个..."**

---

## 一、填空题（每空 2 分，共 20 分）

1. 创建列表用 _____ 括号，元素之间用 _____ 分隔。

2. 列表的索引是从 _____ 开始的。

3. `colors = ["red", "blue", "green"]` 中，`colors[0]` 的值是 _____，`colors[-1]` 的值是 _____。

4. 如果一个列表有 8 个元素，最后一个元素的正索引是 _____，负索引是 _____。

5. 遍历列表的 for 循环格式是：`for 变量 ____ 列表名:`。

6. 通过索引修改列表元素：把 `fruits[1]` 改成 `"pear"`，应该写 `fruits[1] ____ "pear"`。

7. 列表可以装不同类型的数据，这种说法是 _____ 的（填"正确"或"错误"）。

---

## 二、选择题（每题 3 分，共 24 分）

**第1题** 下面哪个是创建 Python 列表的正确方式？

A. `colors = ("red", "blue", "green")`
B. `colors = ["red", "blue", "green"]`
C. `colors = {red, blue, green}`
D. `colors = "red", "blue", "green"`

**第2题** `colors = ["red", "blue", "green"]`，`colors[0]` 的值是？

A. `"red"`    B. `"blue"`    C. `"green"`    D. 报错

**第3题** `colors = ["red", "blue", "green"]`，`colors[-1]` 的值是？

A. `"red"`    B. `"blue"`    C. `"green"`    D. 报错

**第4题** `nums = [10, 20, 30, 40, 50]`，下面哪个取值会报错？

A. `nums[0]`    B. `nums[4]`    C. `nums[5]`    D. `nums[-1]`

**第5题** 下面代码的运行结果是？

```python
fruits = ["apple", "banana", "cherry"]
for f in fruits:
    print(f)
```

A. 输出 `"apple"` 三次
B. 依次输出 `apple`、`banana`、`cherry`
C. 输出 `fruits` 三次
D. 报错

**第6题** 下面哪个负索引取值是正确的？

A. `colors[-0]`    B. `colors[-1]`    C. `colors[-6]`（列表有5个元素）    D. `colors[-]`

**第7题** 下面代码运行后，`colors` 的值是什么？

```python
colors = ["red", "blue", "green"]
colors[1] = "pink"
```

A. `["red", "blue", "green"]`
B. `["red", "pink", "green"]`
C. `["pink", "blue", "green"]`
D. `["red", "blue", "pink"]`

**第8题** `len(["a", "b", "c", "d"])` 的结果是？

A. `3`    B. `4`    C. `5`    D. 报错

---

## 三、代码阅读题（每题 4 分，共 24 分）

**第9题** 写出下面代码的输出结果：

```python
colors = ["red", "blue", "green", "yellow"]
print(colors[0])
print(colors[2])
print(colors[-1])
```

输出：
① __________________
② __________________
③ __________________

**第10题** 写出下面代码的输出结果：

```python
nums = [5, 10, 15, 20]
total = 0
for n in nums:
    total = total + n
print(total)
```

输出：__________________

**第11题** 写出下面代码的输出结果：

```python
animals = ["cat", "dog", "fish"]
for i in range(len(animals)):
    print(f"{i}: {animals[i]}")
```

输出：
① __________________
② __________________
③ __________________

**第12题** 写出下面代码的输出结果：

```python
words = ["hello", "world"]
for w in words:
    print(w.upper())
```

输出：
① __________________
② __________________

**第13题** 写出下面代码的运行结果：

```python
nums = [2, 4, 6, 8]
for n in nums:
    print(n * 3)
```

输出：
① __________________
② __________________
③ __________________
④ __________________

**第14题** 下面代码运行后会输出几行？

```python
fruits = ["apple", "banana", "cherry", "durian", "elderberry"]
for f in fruits:
    if len(f) > 5:
        print(f)
```

输出：
① __________________
② __________________
③ __________________

---

## 四、编程题（共 32 分）

**第15题：创建列表并索引取值（8分）**

创建一个名为 `students` 的列表，包含以下元素：`"小明"`, `"小红"`, `"小刚"`, `"小丽"`。

然后分别输出：
- 第1个学生
- 第3个学生
- 最后一个学生

```python
# 请在此处写代码

```

**第16题：遍历列表输出（8分）**

已知 `scores = [88, 92, 75, 60, 95]`，请用 for 循环遍历列表，并判断每个分数是否及格（>=60 为及格）。如果及格输出 `"XX分 - 及格"`，否则输出 `"XX分 - 不及格"`。

```python
scores = [88, 92, 75, 60, 95]

# 请在此处补全代码

```

**第17题：用 turtle 画彩色圆（16分）**

使用颜色列表 `colors = ["red", "orange", "yellow", "green", "blue", "purple"]`，用 turtle 画出6个不同颜色的圆。

要求：
- 每个圆半径 20
- 每个圆之间间隔 50
- 需要 `import turtle`

提示代码框架：
```python
import turtle
t = turtle.Turtle()
t.speed(3)

colors = ["red", "orange", "yellow", "green", "blue", "purple"]

# 调整起始位置
t.penup()
t.goto(-150, 0)
t.pendown()

# 请补全 for 循环代码

```

**请写出完整代码：**

```python

```

---

## 五、挑战题（附加 10 分）

**第18题：列表反转输出**

已知 `nums = [1, 2, 3, 4, 5]`，请用负索引遍历的方式，从最后一个元素开始，倒序输出所有元素。

提示：用 `for i in range(-1, -6, -1):` 或 `for i in range(len(nums)-1, -1, -1):`

```python
nums = [1, 2, 3, 4, 5]

# 请用负索引倒序遍历并输出每个元素

```

---

## 提交说明

- 提交方式：下节课前交给老师
- 编程题需在电脑上运行通过
- 选择题和填空题直接写在题目旁

---

## 教师批阅栏

| 题型 | 满分 | 得分 |
|:----:|:----:|:----:|
| 填空题（1-7） | 20 | |
| 选择题（1-8） | 24 | |
| 代码阅读（9-14） | 24 | |
| 编程题（15-17） | 32 | |
| 挑战题（18） | 10 | |
| **总分** | **110** | |

**评语：** ____________________________________________________________


---

**自我评价：** □ 全都会了  □ 大部分会了  □ 还要再练练
