逻辑运算
-
先修科目
介绍
逻辑运算“且”、“或”、“不成立”是运算类别的布尔积木。这三个积木把其它布尔型积木作为输入值,然后产生答案“true(真)”或“false(假)”。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/e892a783-0116-4df5-8274-035c701f7caf.png" width="550" style="">
积木:“( )且( )”
积木“( )且( )”检测2个条件是否都为“true(真)”。只有当两个输入积木都为“true(真)”,结果才为“true(真)”;否则,结果就为“false(假)”。有4种可能的输入值组合:
- 真 且 真
️ 真 - 真 且 假
️ 假 - 假 且 真
️ 假 - 假 且 假
️ 假
下图是如何使用带变量的积木“且”:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/61ba4624-b1f5-4c9f-acca-db28d9de3da3.gif" width="900" style="border-radius: 5px; border: 1px solid #29622d;">
积木:“( )或( )”
积木“( )或( )”检测2个条件是否至少有一个为“true(真)”。只要有一个输入积木为“true(真)”,结果就为“true(真)”;只有当两个输入积木都为“false(假)”,结果才为“false(假)”。有4种可能的输入值组合:
- 真 或 真
️ 真 - 真 或 假
️ 真 - 假 或 真
️ 真 - 假 或 假
️ 假
下图是何使用带变量的积木“或”:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/870058ba-396b-4efc-b892-fb120c515ae5.gif" width="900" style="border-radius: 5px; border: 1px solid #29622d;">
积木:“( )不成立”
积木“( )不成立”得出的结果与输入积木相反。如果输入积木为“true(真)”,积木“不成立”得出结果就为“false(假)”。如果输入为“false(假)”,积木“不成立”得出结果就为“true(真)”。
几个例子如下:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/35d3f07c-fb14-4690-973b-0ed84ad4fcc0.gif" width="900" style="border-radius: 5px; border: 1px solid #29622d;">
多个逻辑积木组合
为了同时检测更多条件,可以把多个逻辑运算积木嵌套使用。
几个例子如下:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/e87ef391-2782-436c-9663-20a70b9a59f6.gif" width="900" style="border-radius: 5px; border: 1px solid #29622d;">
带变量时的常见错误
当使用带变量的逻辑运算积木时,几个常见错误如下:
1. X>10 且 X<10
变量X不能同时既大于10又小于10。所以,无论X的值为多少,这个条件永远为“false(假)”。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/05fa6449-4b5c-4530-ac1f-7ff45ceea5cc.gif" width="700" style="border-radius: 5px; border: 1px solid #29622d;">
2. X>20 或 X=20
条件“X>20 或 X=20“可以换成积木”>=“,更简单。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/547e0226-7055-4a62-a486-54c09d3e901a.gif" width="700" style="border-radius: 5px; border: 1px solid #29622d;">
3. X>10 且 X>20
条件“X>10 且 X>20”可以简化成“X > 20”,因为,结果要为真的话,X必须大于20,第一部分“X>10”就是多余的。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/20f2542d-e9ad-4357-a75b-cb91bdd92c3b.gif" width="700" style="border-radius: 5px; border: 1px solid #29622d;">
- 真 且 真
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login