想想這樣。如果
a != b or b != c or a != c
是假的,那麼
a == b and b == c and a == c
DeMorgan's Laws解釋爲什麼是這種情況。請記住,
~(A \/ B) <-> ~A /\ ~B
~(A /\ B) <-> ~A \/ ~B
凡<->基本意思是「彼此相等」,~
的意思是「不」,\/
手段「或」和/\
手段「和」。
要經過這樣的代碼:
def green_ticket_value(a, b, c):
if a != b or b != c or a != c:
return 0
# It can *never* be the case that a != c or a != b at this point
elif a == b and a != c or b == c and b != a or a == c and a!= b:
return 0 // Should this be "return 10"?
# What did you mean to do here?
else: a == b == c
return 20
這是一個有點不清楚你是否意味着
a == b and a != c or b == c and b != a or a == c and a!= b
意味着
(a == b and a != c) or (b == c and b != a) or (a == c and a!= b)
這將永遠是假的(A ==ç和a == b,這意味着所有這些條件都是錯誤的),或者t他以下幾點:
a == b and (a != c or b == c) and (b != a or a == c) and a!= b
這也是始終爲假(其實,這是自相矛盾的地方,因爲它包含a == b && a != b
),或者如果你的意思是一些其他的變種。我會強烈建議在這裏使用parenthases更清楚你想要做什麼。
此外,對於最後一部分:
(b == c and b != a) or (a == c and a != b)
a != b
和b != a
意味着同樣的事情,因此,上述表態意味着同樣的事情
a != b and (a == c or b == c)
沒有'回報10'在你的功能。錯字? –