德摩根';Python中的s定律没有按我认为应该的那样工作
因此,德·摩根定律认为非(A和B)与非A或非B相同。当我尝试使用此代码实现它时,它不起作用。当我输入a为3,b为5时,我在输出中得到False。我遗漏了什么?如何正确地做德摩根';Python中的s定律没有按我认为应该的那样工作,python,Python,因此,德·摩根定律认为非(A和B)与非A或非B相同。当我尝试使用此代码实现它时,它不起作用。当我输入a为3,b为5时,我在输出中得到False。我遗漏了什么?如何正确地做 a = int(input("First num: ")) b = int(input("Second num: ")) print((not (a > 3) or not (b > 7)) == (not ((a <= 3) and (b <= 7 )) ) ) a=int(输入(“第一个
a = int(input("First num: "))
b = int(input("Second num: "))
print((not (a > 3) or not (b > 7)) == (not ((a <= 3) and (b <= 7 )) ) )
a=int(输入(“第一个数值:”)
b=int(输入(“第二个数值:”)
print((not(a>3)或not(b>7))==(not((aa和b)两个语句中的表达式应该相同。
试着改变
print((not (a > 3) or not (b > 7)) == (not ((a <= 3) and (b <= 7 )) ) )
正如你所说,德摩根定律说,非(A和B)
与非A或非B
相同。你正在尝试非A或非B==非(C和D)
这是德摩根定律
a = int(input("First num: "))
b = int(input("Second num: "))
print((not (a > 3) or not (b > 7))== (not ((a > 3) and (b > 7))))
让我们先从低挂果实开始:您的语句实际上并不是表示不是A或不是B==not(A和B)
,而是类似不是C或不是D==not(A和B)
因此,为了测试德摩根定律,您必须确保比较的两边A
和B
都是相同的,例如:
(not (a <= 3) or not (b <= 7)) == (not ((a <= 3) and (b <= 7)))
(not)(a)您正在做的事情类似于非a或非B==非(C和D)
或者甚至非a或非B==非(非a和非B)
。在您的示例中,什么是a
,什么是B
?
(not (a <= 3) or not (b <= 7)) == (not ((a <= 3) and (b <= 7)))
not (a <= 3) == (a > 3)
not (b <= 7) == (b > 7)
((a > 3) or (b > 7)) == (not ((a <= 3) and (b <= 7)))