【发布时间】:2017-07-07 00:35:01
【问题描述】:
给定两个输入布尔值,我想打印出以下结果:
真真->假
真假->假
假真->假
假 假 -> 真
我试过这样做:
if boolInput1 and boolInput2 == True:
print(False)
elif boolInput1 == True and boolInput2 == False:
print(False)
elif boolInput1 == False and boolInput2 == True:
print(False)
elif boolInput1 and boolInput2 == False:
print(True)
但它不起作用,因为这是输出:
Test Input Expected Actual
1 True True False False
2 True False False False
3 False True False False
4 False False True False
我尝试在网上搜索答案,但找不到任何东西。
【问题讨论】:
-
print(not boolInput1 and not boolInput2) -
@cᴏʟᴅsᴘᴇᴇᴅ 第一种情况将返回
True,其他情况返回False。 -
@smarx 对不起,我看错了。
标签: python boolean operator-keyword logical-operators