Lesson 66: Check it twice
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Validation or verification?
- Validation checks that data is sensible: a range check, a length check, a type check (lesson 40).
- Verification checks that data was entered correctly: it is what the user meant to type.
- A password "cat12" can pass validation but still be a typing mistake. Verification catches that.
| Check | How it works |
|---|---|
| double entry | type the data twice; accept it only if both are the same |
| visual check | show the data again; the user looks and confirms it |
English
In the exam
- 0478/21/M/J/25 Q2(b): describe one verification check for a new password. Mark scheme: visual check: look at the data entered and confirm it matches; or double entry check: enter the data twice and only accept identical values.
- 0478/22/M/J/23 Q4(b): (i) a double entry check is used for verification. (ii) Write the code. Mark scheme: iteration; two inputs; check that the two inputs are the same; repeat until they match.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
A double entry check: the user types a new password twice. The program keeps the first one in first. Finish the part for the second entry: if both are the same, print Password saved and light the green LED (pin 12). If not, print Passwords do not match, light the red LED (pin 13) and ask again with Enter a new password.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
A visual check: after the user types a room number, show it back and ask You typed 42. Correct? (Y/N). If the answer is Y, print Saved: and the number. If not, ask for the room number again.
点击“运行”查看此处输出。