昊天SEO

练习28: 布尔(Boolean)表示式练习–笨方法学ruby在线

上一节你学到的逻辑组合的正式名称是「布尔逻辑表示式(boolean logic expression)」。在程序中,布尔逻辑可以说是无处不在。它们是电脑运算的基础和重要组成部分,掌握它们就跟学音乐掌握音阶一样重要。

在这节练习中,你将在 IRB 里使用到上节学到的逻辑表示式。先为下面的每一个逻辑问题写出你认为的答案,每一题的答案要嘛为 True 要嘛为 False。写完以后,你需要将 IRB 运行起来,把这些逻辑语句输入进去,确认你写的答案是否正确。

true and true
false and true
1 == 1 and 2 == 1
"test" == "test"
1 == 1 or 2 != 1
true and 1 == 1
false and 0 != 0
true or 1 == 1
"test" == "testing"
1 != 0 and 2 == 1
"test" != "testing"
"test" == 1
not (true and false)
not (1 == 1 and 0 != 1)
not (10 == 1 or 1000 == 1000)
not (1 != 10 or 3 == 4)
not ("testing" == "testing" and "Zed" == "Cool Guy")
1 == 1 and not ("testing" == 1 or 1 == 0)
"chunky" == "bacon" and not (3 == 4 or 3 == 3)
3 == 3 and not ("testing" == "testing" or "Ruby" == "Fun")

本文地址官网    新乡网站建设,seo

分享到:更多 ()
a