Boolean logic
Python for IGCSE CS Lesson 14 2:19 English narration · English + 中文 subtitles burned in
Chapters
Transcript
A Boolean value is either true or false, and there are exactly three operators that combine them.
布尔值不是真就是假,而组合它们的运算符正好只有三个。
AND is true only when both sides are true.
AND 只有两边都为真时才为真。
OR is true when at least one side is.
OR 只要至少有一边为真就为真。
NOT takes one value and flips it.
NOT 接收一个值,把它取反。
You have been using all three since lesson three, inside conditions — here they get their own names, because the exam asks about the gates themselves.
从第 3 课起你就一直在条件里用这三个—— 这里它们有了自己的名字, 因为考试要考的是这些逻辑门本身。
A truth table lists every possible input and what comes out.
真值表列出所有可能的输入,以及对应的输出。
Two inputs give four combinations, and they are always written in that order: nought nought, nought one, one nought, one one.
两个输入有四种组合,而且总是按这个顺序写: 00、01、10、11。
Fill in the output column and you have described the gate completely.
把输出那一列填好,你就把这个门完整地描述出来了。
AND is true on the last row only — which is exactly what "both must be true" looks like as a table.
AND 只在最后一行为真—— 而这正是"两个都必须为真"画成表格的样子。
Three more gates are named in the syllabus, and two of them are easy: NAND is AND with a NOT round it, and NOR is OR, flipped.
考纲还点了另外三个门的名字,其中两个很简单: NAND 就是 AND 外面套一个 NOT, 而 NOR 就是 OR 取反。
Look at their columns — each one is the opposite of the gate it is named after, top to bottom.
看它们那一列——每一个都是它所对应的门从上到下逐行取反。
XOR is the odd one out.
XOR 是特别的那个。
It is true when the two inputs DIFFER, so it is true on the middle two rows and false on the outside ones.
它在两个输入不同的时候为真, 所以中间两行为真,外面两行为假。
Each of the three tasks is a single line, and for the same reason as lesson six: the operator already gives back a Boolean, so you return it directly.
这三道题每一道都只有一行, 原因和第 6 课一样: 运算符本身已经给出了一个布尔值,所以你直接把它返回。
And compare the two columns one last time — the exam's notation for these is nearly the same words.
再最后对照一次两边—— 考卷上的写法,用的几乎就是同样的词。
That closes the course: fourteen lessons, from a first print statement to logic gates, the whole syllabus in Python.
这门课到此结束: 十四课,从第一条 print 语句到逻辑门, 整份考纲,用 Python 走了一遍。
Four things to take with you.
带走四点。
One: AND needs both, OR needs at least one, and NOT flips.
第一:AND 要两个都真,OR 只要至少一个,NOT 是取反。
Two: a truth table lists every combination of the inputs.
第二:真值表列出输入的每一种组合。
Three: NAND and NOR are those two with a NOT round them, and XOR is true when the inputs differ.
第三:NAND 和 NOR 是那两个外面套上 NOT, 而 XOR 在两个输入不同时为真。
Four: that is fourteen lessons — the whole syllabus, written in Python.
第四:这就是十四课——整份考纲,用 Python 写完了。
Now write the three gates.
现在把那三个门写出来。