mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Update commutative.py
This commit is contained in:
parent
2a4ea96dbd
commit
adb0b64452
@ -1,14 +1,15 @@
|
|||||||
def commutative_law_and(a, b):
|
def commutative_law_and(a: bool, b: bool) -> bool:
|
||||||
"""
|
"""
|
||||||
Implement the commutative law for AND: A AND B = B AND A.
|
Implement the commutative law for AND: A AND B = B AND A.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
a (bool): The first boolean value.
|
a (bool): The first boolean operand.
|
||||||
b (bool): The second boolean value.
|
b (bool): The second boolean operand.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: Result of A AND B.
|
bool: Result of the commutative law (A AND B).
|
||||||
|
|
||||||
|
Examples:
|
||||||
>>> commutative_law_and(True, False)
|
>>> commutative_law_and(True, False)
|
||||||
False
|
False
|
||||||
>>> commutative_law_and(False, True)
|
>>> commutative_law_and(False, True)
|
||||||
@ -20,18 +21,18 @@ def commutative_law_and(a, b):
|
|||||||
"""
|
"""
|
||||||
return a and b
|
return a and b
|
||||||
|
|
||||||
|
def commutative_law_or(a: bool, b: bool) -> bool:
|
||||||
def commutative_law_or(a, b):
|
|
||||||
"""
|
"""
|
||||||
Implement the commutative law for OR: A OR B = B OR A.
|
Implement the commutative law for OR: A OR B = B OR A.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
a (bool): The first boolean value.
|
a (bool): The first boolean operand.
|
||||||
b (bool): The second boolean value.
|
b (bool): The second boolean operand.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: Result of A OR B.
|
bool: Result of the commutative law (A OR B).
|
||||||
|
|
||||||
|
Examples:
|
||||||
>>> commutative_law_or(True, False)
|
>>> commutative_law_or(True, False)
|
||||||
True
|
True
|
||||||
>>> commutative_law_or(False, True)
|
>>> commutative_law_or(False, True)
|
||||||
@ -43,10 +44,6 @@ def commutative_law_or(a, b):
|
|||||||
"""
|
"""
|
||||||
return a or b
|
return a or b
|
||||||
|
|
||||||
|
|
||||||
# Implement other laws similarly
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user