- 学一学28 分钟 · delete、insert、replace、delete all
- 基础任务24 分钟 · 答对的题会离开
- 挑战 1–327 分钟 · 加分题、错字、新的一局
- 加分任务加分 · 你自己的复习清单
复习:我们学到哪里了 5 分钟
add [thing] to [questions v]在最后加上一行。(item (3) of [questions v])读出一行。行号从 1 开始。(length of [questions v])带动任何长度的循环。
快问快答
你的列表有 4 行。(item (5) of [questions v]) 会给你什么?
看答案
什么也没有。你会得到一个空的答案,而且没有报错。所以差了一行的时候,很难发现。
今天的主题 3 分钟
delete (1) of [questions v],还有它对行号做了什么insert [thing] at (2) of [questions v]:把后面的往下推replace item (2) of [questions v] with [thing]:在原位置替换delete all of [questions v]:从头开始
学习目标
学完这一课,你会:
- 从列表里拿走一行,并说出它下面的行发生了什么。
- 在 insert 和 replace 之间做选择,并说出为什么。
- 做一个由列表记录进度的游戏:列表里剩下的,就是还要做的。
学一学:拿东西出来,放东西进去 28 分钟
1 · delete,还有谁也想不到的事
Variables 里有一个积木,可以拿走一行:
delete (1) of [questions v]
几乎每个人都会在这里出错。列表不会留下空位。下面的所有行都会往上移一行。所以一秒钟前还是第 2 项的题,现在是第 1 项了。你脑子里记的行号全都不对了。
怎么用: 点绿旗。第 1 行消失的时候,看左边的盒子。
2 · insert 把后面的往下推
insert [BONUS: how many days in a week?] at (2) of [questions v]
3 · replace 换掉一行
replace item (1) of [questions v] with [What colour is a lemon?]
| 积木 | 下面的行 | 长度 |
|---|---|---|
delete (2) of [questions v] | 往上移 | 少一行 |
insert [q] at (2) of [questions v] | 往下移 | 多一行 |
replace item (2) of [questions v] with [q] | 不移动 | 不变 |
怎么用: 点绿旗,看着盒子。先是 insert,然后是 replace。每次都数一数有几行。
4 · delete all,还有重新开始
上一课你见过这个积木。它让你的问答游戏不会越变越大。不用点绿旗就开始第二局,也要靠它:
when [r v] key pressed
delete all of [questions v]
add [What colour is a banana?] to [questions v]
add [How many legs has a spider?] to [questions v]
基础任务:答对的题会离开 24 分钟
打开你的问答游戏。你要改变列表的意思。以前它是“所有的题”。现在它是“你还没答对的题”。
第 1 步:总是问第 1 行
- 找到你的循环,把计数器拿掉。
- 把 say 改成
(item (1) of [questions v])。 - 运行它。它会一直问同一道题。本来就应该这样。
第 2 步:答对了就删掉
- 在问题后面,加上
ask [Your answer?] and wait。 - 在答对的那一半里,加上
delete (1) of [questions v]。 - 在答错的那一半里,不要动列表。
第 3 步:答错了就排到后面
- 在答错的那一半里,把这道题加到最后。用
add (item (1) of [questions v]) to [questions v]。 - 然后加上
delete (1) of [questions v]。 - 现在,答错的题会排到队伍最后,再轮回来。
第 4 步:盒子空了就停
- 用
repeat until <(length of [questions v]) = (0)>把所有积木包起来。 - 在它后面,说一句庆祝的话。
第 5 步:让大家看到过程
- 确认列表框打了勾,显示在舞台上。
- 玩一轮。看着你答对的行一行一行消失。
repeat until <(length of [questions v]) = (0)>
say (item (1) of [questions v]) for (1.5) seconds
ask [Your answer?] and wait
if <(answer) = (item (1) of [answers v])> then
say [Right - that one is done.] for (1) seconds
delete (1) of [questions v]
delete (1) of [answers v]
else
say [Not quite. It will come round again.] for (1) seconds
end
end
say [All of them, finally!] for (3) seconds
怎么用: 点绿旗。看三轮过去。每答对一次,盒子里就少一行。
问答游戏一直问同一道题。
没有东西被删掉。检查 delete 积木是不是在答对的那一半里,还有它删的是不是第 1 行。
一轮以后,答案和题目就对不上了。
你从 questions 里删了,可是没从 answers 里删。两个一行对一行的列表,必须一起变短。
盒子看起来空了,循环却一直不结束。
repeat until 检查的是另一个列表。或者它比较的不是 0。给两个列表框都打勾,看看哪一个还有行。
答错的题再也没有回来。
add 积木必须在 delete 之前运行。不然,你加的是一行已经没了的东西。
游戏中途的加分题
插进一道惊喜题。不要动已经答过的题。
- 问了两道题以后,一道加分题排在下一个。
- 还没问的题保持原来的顺序。
- 已经做过的题不会再问。
怎么用: 点绿旗。问了两道题以后,加分题就插进来了。看着盒子。
Teacher note
Insert at ((n) + (1)) rather than at a typed row number — the whole point is that the bonus goes in front of whatever is next, wherever the player has got to.
改掉错字
你的一道题有拼写错误。不用重新开始问答游戏,就把它改好。
- 找到有错字的那一行。
- 在原来的位置改正它。
- 改完以后,列表长度不变,什么都没有移动。
怎么用: 点绿旗,看第 4 行。你会先看到错的拼写,然后是对的。
Teacher reveal — why not delete and add?
replace item (4) of [questions v] with [What do cows drink?]
Because delete then add puts it on the bottom, and if the answers list has not moved too, question 4 now has question 4’s old answer. This is the cheapest possible demonstration of why the right block matters.
再玩一次
让玩家不用碰绿旗,就能开始新的一局。
- 按 R 清空列表,再重新装满。
- 一个计数器说出这是第几局。
- 旧的题不会重复出现两次。
怎么用: 点绿旗,再点一下舞台。三道题一道一道消失,然后按 R。
Teacher reveal
when [r v] key pressed
change [plays v] by (1)
delete all of [questions v]
add [What colour is a banana?] to [questions v]
add [How many legs has a spider?] to [questions v]
say (join [Game ] (join (plays) [. All five back.])) for (2.5) seconds
This is the same stocking blocks as the green flag, which is a fair prompt for Lesson 3-14: a job done in two places is a job that wants a My Block. Worth planting now, not solving.
你自己的复习清单
一边玩,一边建第二个列表。它只装你答错的题。最后,这个列表才是最值得留下的东西。
- 一个叫
missed的列表,开始时清空。 - 答错一道,就把这道题加进去。
- 最后,主持人说出有几道要复习。
怎么用: 点绿旗,看两个盒子。一个显示题目一道道过去,另一个是 missed 列表慢慢装满。
Teacher reveal
when flag clicked
delete all of [missed v]
...
else
say [Missed that one.] for (1) seconds
add (item (n) of [questions v]) to [missed v]
end
The delete all of [missed v] at the top is the same trap as last lesson, on a second list — and pupils who fixed it once still forget it here. Let them press the flag twice.
总结 5 分钟
delete (1) of [questions v]拿走一行。它下面的全部往上移。insert [q] at (2) of [questions v]把后面的往下推,列表变长。replace item (2) of [questions v] with [q]换掉一行,别的什么都不变。delete all of [questions v]把列表清空,准备重新装满。- 列表可以记录游戏的进度。盒子里剩下的,就是还要做的。
- 删除(Delete)
- 拿走一行。下面的行往上移。
- 插入(Insert)
- 在指定的编号放进一行。下面的行往下移。
- 替换(Replace)
- 换掉一行里的内容。长度不变。
- 队列(Queue)
- 一个总是从前面拿、往后面加的列表。
交作业
保存你的问答游戏。下一课,答案不一定只有一种拼法。一个积木会帮你在一整个“可以接受的答案”列表里查找。